Using Python's Turtle Graphics


Turtle graphics ( see http://en.wikipedia.org/wiki/Turtle_graphics) is a graphics package for creating vector graphics. It has been widely used for teaching purposes as well as to create artistic designs and works.

There are three things we need to know about a turtle:

  1. its position
  2. its directions
  3. the state of its "pen" for drawing while it moves. (The state of the pen concerns aspects such as the color of the line or fill of the shape, the width of the line, etc)
Here are some suggestions to get started:

Some of the commands to consider:

forward(n)
moves the turtle forward - n steps
left(n)
turns the turtle left by n degrees
right(n)
turns the turtle right by n degrees
pu()
    or penup()
pen up (so the turtle won't write)
pd()
    or pendown()
pen down (so the turtle will write)
color(c)
sets the current color
     example:    color("red")
begin_fill() ... end_fill()
fills a shape with the current color

ht()
   or hideturtle()

hides the turtle (usually done as the second-to-last line)


st()
   or showturtle()
show the turtle
circle(size) creates a circle of radius "size"    
    example:    circle(20)
circle(size, extent) creates a part of a circle of radius "size" and of angle "extent"
(starting at the current angle)
    example:    circle(20, 180)   creates half a circle
speed("fastest") put this at the beginning of your program to speed things up!
write(text, parameters) write text at turtle position. example:
write("that's all folks!", align="center", font=("Courier", 18, "bold"))
done()
when the program is done; this should be the last line of your program.


Color keywords you can use


Further information: