Advertisement
here2share

# t_chase.py *updated*

Jan 19th, 2024
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # t_chase.py *updated*
  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[int(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. while 1:
  51.     if ccc < 280:
  52.         for i in range(n-1):
  53.             angle = chasers[i].towards(chasers[i+1])
  54.             chasers[i].seth(angle)
  55.     zzz = chasers[n-1].pos()
  56.     for z in zzz:
  57.         if abs(z) > 200:
  58.             angle = chasers[n-1].towards(0,0)
  59.             chasers[n-1].seth(angle)
  60.             orbit = random.choice(ppp)
  61.     chasers[n-1].left(orbit)
  62.     chasers[n-1].fd(10)
  63.     for i in range(n-1):
  64.         chasers[i].fd(10)
  65.     ccc = ccc%300 + 1
  66.     screen.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement