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 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.
Code such as this:
Would do the following:
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.
Would have the turtle end up at (-6, 0), aimed right. A line segment would be drawn from (0, 0) to (-6, 0).
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.
Next tutorial: right and left
Here is a link to a related article at EZ Programing Demos: