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 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
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:
You have attempted of activities on this page.