Animations and Interactive Programming

Animating the Spiral Web

Recall the spiral web

import turtle
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
pen = turtle.Pen() 
turtle.bgcolor('black') 
pen.speed(20)

for x in range(360):
    pen.pencolor(colors[x%6])
    pen.width(x/100 + 1) 
    pen.forward(x) 
    pen.left(59) 


turtle.done()

Let's make a rotation animation of the entire web:


import turtle
import time

screen = turtle.Screen()
screen.tracer(0)
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
turtle.bgcolor('black')
turtle.speed(20)
n = 0

while n < 400:
    turtle.goto(0, 0)
    turtle.clear()
    for x in range(360):
        turtle.pencolor(colors[x % 6])
        turtle.pensize(x / 100 + 1)
        turtle.forward(x)
        turtle.left(59)
    screen.update()
    time.sleep(0.01)
    turtle.left(1)
    n = n + 1

turtle.done()