More Turtle Procedures and Functions

Turtles can do more than go forward, turn left, and turn right. The table below lists more turtle procedures and functions.

Name Input Description
backward amount Moves the turle backward by the specified amount
color colorname Sets the color for drawing. Use ‘red’, ‘black’, etc
forward amount Moves the turtle forward by the specified amount
goto x,y Moves the turtle to position x,y
left angle Turns the turtle counter clockwise by the specified angle
pendown None Puts down the turtles tail so that it draws when it moves
penup None Picks up the turtles tail so that it doesn’t draw when it moves
pensize width Sets the width of the pen for drawing
right angle Turns the turtle clockwise by the specified angle
setheading angle Turns the turtle to face the given heading. East is 0, north is 90, west is 180, and south is 270.
Turtle None Creates and returns a new turtle object

You can draw a block style C with a turtle. Can you draw more than one letter? You would have to use the penup() procedure to pick up the pen and then move to the new location to draw the second letter and then put the pen down using pendown() as shown in the example below.

The space that the turtle draws in is 320 by 320 pixels. The center of the space is at x=0, y=0.

the space coordinate system

Figure 1: The coordinates for the drawing space. Note that the center is x = 0 and y = 0.

The program below uses the goto(x,y) to move to the top left corner before drawing a square that nearly fills the drawing space.

Note

Remember to put the pen down again after you have picked it up if you want to draw a line!

Mixed up programs

        csp-5-3-1: The following program uses a turtle to draw a capital F as shown in the picture to the left of this text,  but the lines are mixed up.  The program should do all necessary set-up: import the turtle module, get the space to draw on, and create the turtle.  It should draw the lines in the order shown by the numbers in the picture on the left.

Drag the needed blocks of statements from the left column to the right column and put them in the right order. There may be extra blocks that are not needed in a correct solution. Then 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 the wrong blocks.

from turtle import * space = Screen() anu = Turtle() --- anu.left(90) anu.forward(100) --- anu.right(90) anu.forward(50) --- anu.left(90) anu.forward(50) #distractor --- anu.penup() --- anu.penUp() #distractor --- anu.goto(0,60) --- anu.goTo(0,60) #distractor --- anu.pendown() --- anu.penDown() #distractor --- anu.forward(50)
        csp-5-3-2: The following program uses a turtle to draw a capital A as shown in the picture to the left of this text,  but the lines are mixed up.  The program should do all necessary set-up: import the turtle module, get the space to draw on, and create the turtle.  It should draw the lines in the order shown by the numbers in the picture on the left. 

Drag the needed blocks of statements from the left column to the right column and put them in the right order. There may be additional blocks that are not needed in a correct solution. Then 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 the wrong blocks.

from turtle import * --- space = Screen() --- space = screen() #distractor --- ella = Turtle() --- ella = Turtle #distractor --- ella.left(60) ella.forward(100) --- ella.left(60) ella.forward() #distractor --- ella.right(120) ella.forward(100) --- ella.penup() ella.goto(30,50) ella.pendown() --- ella.left(60) ella.forward(40) --- ella.Left(60) ella.forward(40) #distractor

You can change the color and pensize that you draw with as well.

Use the area below to try to draw to draw your initials in block style with two different colors.

Note

Discuss topics in this section with classmates.

Show Comments
Next Section - Single and Multiple Turtles