Advertisement
here2share

# t_chase.py

Aug 6th, 2020
2,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # t_chase.py
  2.  
  3. import turtle
  4. import random
  5.  
  6. rainbow=[]
  7. def z(r,g,b):
  8.     rainbow.append((r,g,b))
  9. r,g,b=255,0,0
  10. for g in range(256):
  11.     z(r,g,b)
  12. for r in range(254, -1, -1):
  13.     z(r,g,b)
  14. for b in range(256):
  15.     z(r,g,b)
  16. for g in range(254, -1, -1):
  17.     z(r,g,b)
  18. for r in range(256):
  19.     z(r,g,b)
  20. for b in range(254, -1, -1):
  21.     z(r,g,b)
  22. Lc = len(rainbow)
  23.  
  24. n=300
  25. ccc = Lc/(n+1)
  26.  
  27. screen = turtle.Screen()
  28. screen.tracer(0,0)
  29. screen.setup(600,600)
  30. screen.title('Chase')
  31. turtle.hideturtle()
  32.  
  33. chasers = []
  34. for i in range(n):
  35.     chasers.append(turtle.Turtle())
  36.  
  37. for i in range(n):
  38.     c = '#%02x%02x%02x' % (rainbow[i*ccc])
  39.     chasers[i].up()
  40.     chasers[i].color(c)
  41.     chasers[i].goto(random.uniform(-500,500), random.uniform(-500,500))
  42. chasers[n-1].goto(0,0)
  43. chasers[n-1].shape('circle')
  44. chasers[n-1].shapesize(1)
  45.  
  46. orbit=2
  47. ppp = range(1,9)
  48. ccc = 0
  49.  
  50. def chase():
  51.     global orbit, ccc
  52.     if ccc < 290:
  53.         for i in range(n-1):
  54.             angle = chasers[i].towards(chasers[i+1])
  55.             chasers[i].seth(angle)
  56.     zzz = chasers[n-1].pos()
  57.     for z in zzz:
  58.         if abs(z) > 200:
  59.             angle = chasers[n-1].towards(0,0)
  60.             chasers[n-1].seth(angle)
  61.             orbit = random.choice(ppp)
  62.     chasers[n-1].left(orbit)
  63.     chasers[n-1].fd(10)
  64.     for i in range(n-1):
  65.         chasers[i].fd(10)
  66.     ccc = ccc%300 + 1
  67.     screen.update()
  68.     screen.ontimer(chase,0)
  69.    
  70. chase()
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement