Some Useful Settings and Methods for Turtle
These tables show some of the values for various methods used in the Python turtle package.
The methods that require a speed with which to move the cursor (turtle) take an integer argument. The integer is between 0 and 10, with 0 meaning no animated motion and 10 meaning the fastest animated motion. So if you have the speed set to 0, the turtle will jump around as you move it; there will be no animation.
- tur.speed(n) sets the speed of the turtle tur to n, where n is as above.
The methods that require a color use a color specification string. The more common ones are:
A full list can be found at http://www.tcl.tk/man/tcl8.5/TkCmd/colors.htm. You can also specify colors as mixtures or red, green, and blue as #rrggbb, where rr, gg, and bb are two hexadecimal digits each indicating the intensity of the color (with “00” meaning the color isn’t present and “FF” meaning it is as intense as possible).
|black || cyan || green || pink || violet|
|blue || gold || magenta || purple || white|
|brown || gray || orange || red || yellow|
- win.bgcolor(col) sets the background color of window win to col, where col is as above.
- tur.color(col) sets the color of the turtle tur, and any lines or other shapes drawn with it subsequently, to col, where col is as above.
The methods that require a shape for the cursor (turtle) know the following shapes:
|arrow || turtle || circle || square || triangle || classic|
- tur.shape(img) sets the shape of the turtle tur to img, where img is as above.
A “pen” is associated with each turtle.
The pen can be in the “up” state or the “down” state.
When you move the cursor (turtle), if the pen is down,
the turtle draws a line from the current position to the new one.
If the pen is up, the position of the turtle changes to the new one,
but no line is drawn.
You can draw a dot or a circle of a given size, too.
You can also write text at the current location of the mouse.
- tur.goto(x, y) moves the turtle tur from the current co-ordinates to (x, y).
- tur.penup() raises the pen (puts it into the “up” state) associated with the turtle tur. When you move the turtle, the co-ordinates change but no line is drawn.
- tur.pendown() lowers the pen (puts it into the “down” state) associated with the turtle tur. When you move the turtle, the co-ordinates change and a line is drawn from the current co-ordinates to the given co-ordinates.
- tur.dot(n) draws a dot at the current position of the turtle tur. If n is present, the dot has diameter n pixels. If n is not present, the dot has a default size (the maximum of pensize + 4 and 2\timespensize, where pensize is the width used to draw a line, if you must know).
- tur.circle(n) draws a circle of radius n pixels, with the center n pixels left of the current position of the turtle tur.
- tur.write(string, move, align, (fontname, fontsize, fonttype)) writes the given string at the current position of the turtle tur. It is positioned as indicated by align, which may take the (string) values "left", "center", or "right". The text is printed in the named fontname, with point size fontsize, in the type fonttype. Then, if move is True, the position of the turtle tur changes to the bottom right corner of the text. If move is omitted, it defaults to False; if align is omitted, it defaults to "left"; and if the font triplet is omitted, the font Ariel, with point size 8, in normal type, is used.
Coloring in Shapes (Filling Shapes)
You can color in, or “fill”, a shape such as a rectangle or circle (or, really, anything).
To do this, say you want to begin filling the shape then draw the shape, then say you are done.
Filling is associated with a turtle, so if you have several active turtles, the filling is done only for the one(s) you indicate.
By default, the fill color is the color of the turtle. You can change it to another color as described in the section Color, above.
- tur.begin_fill() says to begin filling the shape subsequently drawn using turtle tur.
- tur.end_fill() says to stop filling the shape drawn using turtle tur.
- tur.fillcolor(col) sets the fill color associated with the turtle tur to col, where col is as in the Color section above.
More About Turtle
The reference document for turtle is Chapter 24.1, “Turtle Graphics”, of Python Setup and Usage,
available at https://docs.python.org/3.4/library/turtle.html.