3.14. A Few More turtle Methods and Observations

Here is a table that summarizes common Turtle methods:

Method

Parameters

Description

Turtle

None

Creates and returns a new turtle object

forward

distance

Moves the turtle forward

backward

distance

Moves the turle backward

right

angle

Turns the turtle clockwise

left

angle

Turns the turtle counter clockwise

up

None

Picks up the turtle’s tail (pen)

down

None

Puts down the turtle’s tail (pen)

color

color name

Changes the color of the turtle and pen

fillcolor

color name

Changes the color the turtle will use to fill a polygon

heading

None

Returns the current heading

position

None

Returns the current position

goto

x,y

Move the turtle to position x,y

begin_fill

None

Remember the starting point for a filled polygon

end_fill

None

Close the polygon and fill with the current fill color

dot

None

Leave a dot at the current position

stamp

None

Leaves an impression of a turtle shape at the current location

shape

shapename

Can be set to ‘arrow’, ‘triangle’, ‘classic’, ‘turtle’, ‘circle’, or ‘square’

speed

integer

0 = no animation, fastest; 1 = slowest; 10 = very fast

Here are a few more things that you might find useful as you write programs that use turtles.

Let’s do an example that shows off some of these new features. Note that the code below uses a for loop to make the turtle move repeatedly 30 times. We’ll cover for loops in the next chapter.

One more thing to be careful about. All except one of the shapes you see on the screen here are footprints created by stamp. After the loop, we change tess to be red, and that way you see where the actual turtle is (the red one is not a stamp - it’s tess!).

Mixed up program

The following program uses the stamp method to create a circle of turtle shapes as shown to the left:

image of a circle of turtle shapes

But the lines are mixed up. The program should do all necessary set-up, create the turtle, set the shape to “turtle”, and pick up the pen. Then the turtle should repeat the following ten times: go forward 50 pixels, leave a copy of the turtle at the current position, reverse for 50 pixels, and then turn right 36 degrees. After the loop, set the window to close when the user clicks in it.

Drag the blocks of statements from the left column to the right column and put them in the right order with the correct indention. Click on Check Me to see if you are right. You will be told if any of the lines are in the wrong order or are incorrectly indented.

Mixed up program

The following program uses the stamp method to create a line of turtle shapes as shown to the left:

image of a line of turtle shapes

But the lines are mixed up. The program should do all necessary set-up, create the turtle, set the shape to “turtle”, and pick up the pen. Then the turtle should repeat the following three times: go forward 50 pixels and leave a copy of the turtle at the current position. After the loop, set the window to close when the user clicks in it.

Drag the blocks of statements from the left column to the right column and put them in the right order with the correct indention. Click on Check Me to see if you are right. You will be told if any of the lines are in the wrong order or are incorrectly indented.

You have attempted of activities on this page