Object-oriented turtle graphics
import time
# Draw a "circle". Turtle graphics are optimized, so the circle that is
# drawn is really a polygon. However you can see the turtle change its
# heading one degree at a time.
def circle():
width = 640
height = 480
world = makeWorld(width, height) # Make a "canvas" for the turtle to draw on
turtle = makeTurtle(world) # Create a turtle in the world.
# Put the turtle somewhere in the middle of the world before drawing
turtle.penUp()
turtle.moveTo(int(width/3), int(height/2))
turtle.penDown()
# Now, draw the circle
for degree in range(0, 360):
turtle.turn(1) # Turn one degree at a time
turtle.forward(2) # A small circle. One pixel is too small.
time.sleep(0.05) # So that we can see the turtle doing the drawing
Link to this Page