The following example illustrates the process of importing and executing turtle commands.
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from turtle import * >>> forward(100) >>> left(90) >>> forward(100)
Complete documentation for the turtle module can be found in the Python Standard Library Documentation. The following functions should be enough to get you started for today's activities:
forward(distance) backward(distance)
|
Move the turtle forward/backward the indicated distance (in pixels). |
left(angle) right(angle)
|
Turn the turtle left/right by the indicated angle (in degrees). |
penup() pendown()
|
After penup() is called, the turtle will not draw until
pendown() is called.
|
goto(x, y)
|
Move the turtle to the indicated position. The orientation is not changed. |
setheading(to_angle)
|
Set the orientation of the turtle to the indicated angle. Zero degrees points to the right, and ninety degrees points up. |
exitonclick()
|
This command prevents the turtle screen from closing until it is
clicked by the user. This should be the last command in
your main .
|
shapes.py
.
rectangle(x, y, width, height)
polygon(x, y, sides, size)
size
parameter.
for
loop or a
while
loop. The best approach is to use
a for
loop along with the range
function to control the number of loop iterations. main
so that it includes several calls
to your newly defined polygon
function.
grid(x, y, rows, columns, size)
.
rows x columns
grid
of squares. The lower-left corner of the grid should be at
position (x,y). The size parameter indicates the width of the
individual squares.
Don't copy/paste code from the
existing square
function! Your grid
function should invoke square
with appropriate
parameter values.
picture()