simple polygon-drawing turtle functions
import time
def square1(turtle):
for i in range(4):
turtle.forward(100)
turtle.turn(90)
time.sleep(1.0)
def triangle1(turtle):
for i in range(3):
turtle.forward(100)
turtle.turn(120)
time.sleep(1.0)
def polygon(turtle, n, length):
for i in range(n):
turtle.forward(length)
turtle.turn(360/n)
def triangle(turtle):
polygon(turtle, 3, 100)
def square(turtle):
polygon(turtle, 4, 100)
# Question (difficult):
# Why does the following not draw a circle?
# (Or at least a 360-sided polygon?)
def circle(turtle):
polygon(turtle, 360, 1)
Link to this Page