EZ Math Movie, Tutorials, Turtle Graphics, forward and back

The turtle at home

The turtle's home is the origin, point (0, 0). The command home sends the turtle to the origin and aims it at a heading of 0 degrees. This heading points the turtle directly right, or straight down the x-axis toward increasing positive values.

The home command is useful for setting the initial state of the turtle at the start of a turtle graphics drawing. The code for home looks like this:


The example program sends the turtle home and then moves it forward and backward.


The turtle at home


The command forward moves the turtle a certain distance in the direction in which it is aimed.

Usually, the turtle is set up to draw on the graph as it moves. When the turtle draws, we say that 'its pen is down'. The turtle's pen is down by default. So, by default it will draw when it is moved with the forward command.

This is the code to move the turtle 7 units:


If the turtle was aimed up (90 degrees heading), then the turtle would draw a line segment 7 units long. The segment would stretch from the turtle's starting point to a point 7 units directly above the starting point. This would be a vertical line. We would imagine the turtle at the top of it, aimed up.


forward(7) animation

So far

Code such as this:


Would do the following:

home(); forward(6);

The turtle at home


The command back works just like forward, except it moves the turtle backward, as if it were a car in reverse.

The turtle does not change its direction when it moves backward. It does not turn around and then go forward.

This code:


Would have the turtle end up at (-6, 0), aimed right. A line segment would be drawn from (0, 0) to (-6, 0).

home(); back(6);

The turtle at home

Running the example program

The program sends the turtle home, then walks it forward down the x-axis a ways, then walks it backward over its forward path and then some. The turtle ends up on the negative x-axis, aimed right.

The turtle draws as it moves, but this may be a bit hard to see since the line segment is drawn directly over the x-axis. We need to learn how to turn the turtle so we can move it off of the x-axis. That is in the next tutorial.

home(); forward(5); back(10);

Turtle motion

The example program

Angle measurement: Degrees Radians

Go on input

Sorry, apparently this browser does not support HTML 5 canvas tag graphics.

Edit: Runtime          View: Starter Suggestion

To runtime:


Editor width: Normal Wide








Next tutorial: right and left


Here is a link to a related article at EZ Programing Demos:

Moving around

All contents of EZ Math Movie are copyrighted: Copyright 2011, Edward A. Zobel. All rights reserved.

Other sites you may find interesting

Zona Land Education Like Math and Physics?

Zona Land Education offers explanations, diagrams, and animations on these topics.
And it is all presented in a clear and casual manner.

Here is the link: zonalandeducation.com

EZ Programing Demos Want to learn about programing computers?

EZ Programing Demos has an animated, slow motion, interactive programing language demonstrator.
The site presents basic ideas at a beginner's level.

Here is the link: ezprogramingdemos.com

Custom Search