Skip to main content

Section 16.4 Turtle Procedures

Turtles can do more than go forward, turn left, and turn right. The table below lists more turtle procedures and functions.
Table 16.4.1. Turtle procedures
Name Input Description
backward amount
Moves the turtle backward by the specified amount. If the pen is down, it draws a line. A move of 0 makes a dot if the pen is down.
forward amount
Moves the turtle forward by the specified amount. If the pen is down, it draws a line. A move of 0 makes a dot if the pen is down.
goto x, y
Moves the turtle to position x, y. Note you must put a comma between the two values.
left angle
Turns the turtle counter-clockwise by the specified angle
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.
speed number
How fast to move the turtle. Should be a value from 1-10 (1 is slow, 10 is fast), or 0 which means “as fast as possible”.
xcor None
A function - returns the current x position of the turtle.
ycor None
A function - returns the current y position of the turtle.
hideturtle None
Hides the turtle (the triangle icon)
pendown None
Puts down the turtle’s pen so that it draws when it moves
penup None
Picks up the turtle’s pen so that it doesn’t draw when it moves
pensize width
Sets the width of the pen for drawing
color colorname
Sets the color for drawing. Use strings - like ’red’, ’black’, etc… This page has a table of colors
 1 
https://trinket.io/docs/colors
Make sure to put quotation marks around the name of the color!
begin_fill None
Tells the turtle to start painting inside the shape it draws
end_fill None
Tells the turtle to stop painting inside the shape it draws
fillcolor colorname
This page has a table of colors
 2 
https://trinket.io/docs/colors
stamp None
Stamps a copy of the turtle’s icon at the current location.
shape shapeName
Changes the icon used to represent the turtle. shapeName should be set to one of the following: “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”.
To draw more than one letter you can use the penup() procedure after drawing the first letter to pick up the pen before moving to where you want to start the next letter. Once you are ready to draw again, use pendown(). The example below draws a C and an S.

Note 16.4.2.

In the sample we use blank lines to break up the code into logical chunks and comments to describe what each chunk does. The computer does not care about these things, but these tricks make it much easier for humans to understand what is happening.
Try some experiments on the code:
  • Change the speed to a different value (1-10)
  • Try looking up some other colors
     3 
    https://trinket.io/docs/colors
    and change what color the turtle draws with.
  • Try commenting out the code in the section called # Draw the S to see how the turtle is repositioned after the C so it can start the S.
You have attempted of activities on this page.