Python and Turtle animation,colorsys,Difficulty Level 7,list,random,while loop Massive Chasing Game (with Source Code)

Massive Chasing Game (with Source Code)

In this Python Turtle project, you are going create a fun and beautiful animation. First, you are going to create a list of 100 turtles and put them into random positions. Set the color of these turtles gradually from hue value 0 to hue value 1. In each iteration, each turtle will move toward a small step toward the next turtle in the list. The last turtle in the list will move toward the first turtle. Repeat the iteration forever. These turtles will converge into a beautiful rainbow colored shape!

Video of this animation:

Source Code:

import turtle
import random
import colorsys

screen = turtle.Screen()
screen.tracer(0,0)
screen.setup(1000,1000)
turtle.hideturtle()

n=100
chasers = []
for i in range(n):
    chasers.append(turtle.Turtle())

h = 0
for i in range(n):
    c = colorsys.hsv_to_rgb(h,1,0.8)
    h += 1/n
    chasers[i].color(c)
    chasers[i].up()
    chasers[i].goto(random.uniform(-500,500), random.uniform(-500,500))

def chase():
    for i in range(n-1):
        angle = chasers[i].towards(chasers[i+1])
        chasers[i].seth(angle)
    angle = chasers[n-1].towards(chasers[0])
    chasers[n-1].seth(angle)
    for i in range(n):
        chasers[i].fd(2)
    screen.update()
    screen.ontimer(chase,1000//20)
    
chase()

Related Post