Animations and Interactive Programming
Drawing a Pair of Spirals
import turtle
wn = turtle.Screen()
wn.bgcolor("light green")
wn.title("Turtle")
turtle1 = turtle.Turtle()
turtle1.color("blue")
turtle2 = turtle.Turtle()
turtle2.up()
turtle2.goto(-200,200)
turtle2.down()
def sqrfunc(size):
for i in range(4):
turtle1.fd(size)
turtle1.left(90)
turtle2.fd(size)
turtle2.left(90)
size = size-5
sqrfunc(146)
sqrfunc(126)
sqrfunc(106)
sqrfunc(86)
sqrfunc(66)
sqrfunc(46)
sqrfunc(26)
turtle.done()
turtle1
and turtle2
are two different instances (objects) of the turtle class.
Practice: Try drawing the spirals inside-out.