The Coordinate System

Logo turtle movements are measured in turtle steps while computer monitors display graphics in pixels. Logo provides several ways to relate turtle steps to graphics pixels. When Logo starts, each turtle step is equal to one screen pixel in any direction. The turtle is in WRAP mode, meaning it appears at the opposite border when it crosses one of the boundaries of the Graphics Window. If the window is enlarged with the mouse or the SETWINSIZE command, any wrapped lines reflect the previous border of the window but wrapping now occurs at the new window border. The HOME position is always in the middle of the Graphics Window regardless of its shape.

The SETWINSIZE command takes two inputs, the X and Y size of the drawing area as pixels. Since by default a turtle step is equal to a pixel, SETWINSIZE also determines the size of the Graphics Window in terms of turtle steps.

Sometimes it is useful to define the size of the Graphics Window in turtle steps regardless of its physical appearance in terms of pixels. Logo provides the SETEXTENT command to define the maximum distance from the HOME position of the turtle to the edge of the Graphics Window in terms of the turtle steps (the extent of the Graphcs Window). The SETEXTENT command takes one argument, the extent. You can, for example, establish that the border of the Graphics Window is 100 turtle steps from the HOME position no matter what the physical size or shape of the Graphics Window with the SETEXTENT 100 command. SETEXTENT can optionally take a second argument if you want to define different extents for the X and Y directions. For example, (SETEXTENT 100 200) defines a window that is 200 steps wide and 400 steps high.

By using the SETEXTENT command and scaling the Graphics Windows to turtle steps, you can be assured that your graphics fit within the Graphics Window no matter how it is resized. This created predictable relationships between your graphics and the Graphics Window but may result in your graphics being compressed or stretched depending on the ratio between the window size in pixels and turtle steps.

TO HEXDESIGN

REPEAT 12[REPEAT 6 [FD 40 LT 60] RT 30]

END

? EXTENT

Result: [0 0]

The (SETWINSIZE) command used in parentheses without inputs restores the default extent of the Graphics Window to one turtle step per pixel.

You can also move the HOME coordinates of one or more turtles with the SETORIGIN command. SETORIGIN takes two inputs, X and Y, and defines the new HOME position for all active turtles. The coordinates are relative to the original HOME position, which is in the center of the Graphics Window. Use the command (SETORIGIN) to revert your turtles to the original HOME position.

? SETWIDTH 10 \

? (DOT)

? SETORIGIN [0 \

? 30]

? GETXY

Result: [0 0]

? ORIGIN

Result: [0 30]

?