Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # t_chase.py
- import turtle
- import random
- rainbow=[]
- def z(r,g,b):
- rainbow.append((r,g,b))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- Lc = len(rainbow)
- n=300
- ccc = Lc/(n+1)
- screen = turtle.Screen()
- screen.tracer(0,0)
- screen.setup(600,600)
- screen.title('Chase')
- turtle.hideturtle()
- chasers = []
- for i in range(n):
- chasers.append(turtle.Turtle())
- for i in range(n):
- c = '#%02x%02x%02x' % (rainbow[i*ccc])
- chasers[i].up()
- chasers[i].color(c)
- chasers[i].goto(random.uniform(-500,500), random.uniform(-500,500))
- chasers[n-1].goto(0,0)
- chasers[n-1].shape('circle')
- chasers[n-1].shapesize(1)
- orbit=2
- ppp = range(1,9)
- ccc = 0
- def chase():
- global orbit, ccc
- if ccc < 290:
- for i in range(n-1):
- angle = chasers[i].towards(chasers[i+1])
- chasers[i].seth(angle)
- zzz = chasers[n-1].pos()
- for z in zzz:
- if abs(z) > 200:
- angle = chasers[n-1].towards(0,0)
- chasers[n-1].seth(angle)
- orbit = random.choice(ppp)
- chasers[n-1].left(orbit)
- chasers[n-1].fd(10)
- for i in range(n-1):
- chasers[i].fd(10)
- ccc = ccc%300 + 1
- screen.update()
- screen.ontimer(chase,0)
- chase()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement