Turtle Graphics - Basic Motion
[Index] [<< Previous section: The Graphics Canvas] [Next section: Curved Paths >>]
forward expr
fd expr
- Description: moves the turtle forward expr pixels, in the direction it is facing.
- Examples:
fd 100
fd -50.25
Note that you can use negative values to go backwards. - Examples:
back expr
bk expr
- Description: moves the turtle backward expr pixels, exactly opposite to the direction that it's facing.
- Examples:
bk 80
bk -35.75
Note that you can use negative values to go forward. - Examples:
left expr
lt expr
- Description: rotates the turtle expr degrees counterclockwise.
- Examples:
lt 90.30
lt -45
Note that you can use negative values to rotate clockwise. - Examples:
right expr
rt expr
- Description: rotates the turtle expr degrees clockwise.
- Examples:
rt 120
rt -60
Note that you can use negative values to rotate counterclockwise. - Examples:
setpos [ expr expr ]
- Description: moves the turtle to the specified location without drawing. The input is a list of two numbers, the X and Y coordinates.
- Example:
setpos [100 100]
- Example:
setxy expr expr
- Description: moves the turtle to the specified location without drawing. The two inputs are numbers, the X and Y coordinates.
- Example:
setxy 100 100
- Example:
setx expr
- Description: moves the turtle horizontally from its old position to a new horizontal coordinate. expr is the new X coordinate.
- Example:
setx 150
- Example:
sety expr
- Description: moves the turtle vertically from its old position to a new vertical coordinate. expr is the new Y coordinate.
- Example:
sety -220
- Example:
setheading expr
seth expr
- Description: turns the turtle to a new heading. expr is a number, the heading in degrees clockwise from the positive Y axis.
- Example:
seth 120
- Example:
home
- Description: moves the turtle to the initial position (canvas center), pointing upwards.
- Example:
home
- Example:
[Index] [<< Previous section: The Graphics Canvas] [Next section: Curved Paths >>]