Turtle Graphics Commands


*Window Management
*Turtle Motion
*Turtle Position Queries
*Turtle State
*Color Palette Operations

Up: *Table of contents


Turtle Tracks includes a full set of turtle graphics primitives, which are part of the primitive group virtuoso.logo.lib.TurtlePrimitives. These commands may not be available for some console types.


Window Management

These commands manage the drawing window.


DRAW
(DRAW xmax ymax)

DRAW opens the drawing window for subsequent turtle graphics commands. If the drawing window is already open, DRAW clears and resets it. If xmax and ymax parameters are given to DRAW, they specify the size of the window, in that x-coordinates range from -xmax to xmax-1 and y-coordinates range from -ymax to ymax-1. Thus, the window opened will have a width of 2*xmax and a height of 2*ymax. If DRAW is called without parameters, xmax and ymax default to 160 and 120, respectively. If a graphics window cannot be opened, or if xmax or ymax are not integer values, DRAW throws an error.


NODRAW

NODRAW closes any open turtle graphics window. If no window is open, NODRAW has no effect.


XSIZE

XSIZE returns the current xmax value for the graphics window. X-coordinates range from -XSIZE to XSIZE-1. Therefore, the width of the window is 2*XSIZE.


YSIZE

YSIZE returns the current ymax value for the graphics window. Y-coordinates range from -YSIZE to YSIZE-1. Therefore, the height of the window is 2*YSIZE.


CLEAN
CS

CLEAN fills the entire graphics window with the current background color. The current turtle position and state are not affected.


CLEARSCREEN
CS

CLEARSCREEN moves the turtle to the home position, and fills the entire graphics window with the current background color.


WRAP

WRAP sets the current window border behavior to "wrap." If the turtle moves past an edge of the window, it will "wrap around", or reappear on the other side.


WINDOW

WINDOW sets the current window border behavior to "window." If the turtle moves past an edge of the window, it will disappear until it is moved back into view.


FENCE

FENCE sets the current window border behavior to "fence." Any call that attempts to move the turtle past the edge of the window will throw an error. If the mode was "window" and the turtle is already past the edge of the window, FENCE will throw an error.


REFRESHINTERVAL value

REFRESHINTERVAL sets the refresh interval in milliseconds. That is, if set to 1000, REFRESHINTERVAL will cause the turtle screen to refresh at most once per second during drawing operations. Setting an interval of 0 causes all drawing to happen immediately. If a negative interval is specified, no drawing will happen automatically, and the REFRESH command should be used to cause the screen to update. The window will, however, always update in response to window manager events, regardless of the setting of REFRESHINTERVAL. If the argument is not an integer, REFRESHINTERVAL throws an error.


REFRESH

REFRESH forces an update of the turtle graphics window. This is typically used in conjunction with a negative REFRESHINTERVAL value, to cause the image to be redisplayed at specific times during the drawing process.

*Top


Turtle Motion

These commands can be used to move the turtle.


FORWARD number
FD number

FORWARD moves the turtle forward the given number of pixels in the current heading direction. If the pen is currently down, the turtle will draw a line along its path. If the given input is not a number, FORWARD will throw an error.


BACK number
BK number

BACK moves the turtle the given number of pixels in the direction opposite from the current heading direction. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path. If the given input is not a number, BACK will throw an error.


RIGHT number
RT number

RIGHT changes the turtle's heading by the specified number of degrees to clockwise. The turtle's position is not changed. If the given input is not a number, RIGHT will throw an error.


LEFT number
LT number

LEFT changes the turtle's heading by the specified number of degrees to clockwise. The turtle's position is not changed. If the given input is not a number, LEFT will throw an error.


SETX number

SETX moves the turtle such that its y-position remains the same but its x-position is the given value. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path. If the given input is not a number, SETX will throw an error.


SETY number

SETY moves the turtle such that its x-position remains the same but its y-position is the given value. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path. If the given input is not a number, SETY will throw an error.


SETXY xcor ycor

SETXY moves the turtle such that its x-position and y-position become the given values. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path. If the given inputs are not numbers, SETXY will throw an error.


SETPOS poslist

SETPOS moves the turtle to the coordinates specified by the input position list. The input must be a two-element list, the first element being the x-coordinate and the second being the y-coordinate. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path. If the given input is not a list or does not contain exactly two numeric elements, SETPOS will throw an error.


SETHEADING number

SETHEADING sets the heading of the turtle to the given value, in degrees. A heading of 0 points straight up, and positive values run clockwise. The position of the turtle is not changed. If the given input is not a number, SETHEADING will throw an error.


HOME

HOME moves the turtle to the origin. It has the same effect as SETXY 0 0. The heading of the turtle is not changed. If the pen is currently down, the turtle will draw a line along its path.


LABEL expr

LABEL draws the specified expression on the screen as text, starting from the current turtle position, in the same form as it would appear if it were PRINTed.

*Top


Turtle Position Queries

These commands can be used to get information about the turtle's position and heading.


XCOR

XCOR returns the current x-coordinate of the turtle.


YCOR

YCOR returns the current x-coordinate of the turtle.


POS

POS returns the current position of the turtle in the form of a two-element list, where the first element is the x-coordinate and the second element is the y-coordinate.


HEADING

HEADING returns the current heading of the turtle, in degrees. A heading of 0 points straight up, and positive values run clockwise.


DISTANCETOXY xcor ycor

DISTANCETOXY returns the distance from the current turtle position to the given coordinates. The position and heading of the turtle are not changed. If the given inputs are not numbers, DISTANCETOXY will throw an error.


DISTANCETO poslist

DISTANCETO returns the distance from the current turtle position to the given coordinates. The input must be a two-element list, the first element being the x-coordinate and the second being the y-coordinate. The position and heading of the turtle are not changed. If the given input is not a list or does not contain exactly two numeric elements, DISTANCETO will throw an error.


TOWARDSXY xcor ycor

TOWARDSXY returns the heading pointing from the turtle position to the given coordinates, in degrees. A heading of 0 points straight up, and positive values run clockwise. The position and heading of the turtle are not changed. If the given inputs are not numbers, TOWARDSXY will throw an error.


TOWARDS poslist

TOWARDS returns the heading pointing from the turtle position to the given coordinates, in degrees. The input must be a two-element list, the first element being the x-coordinate and the second being the y-coordinate. A heading of 0 points straight up, and positive values run clockwise. The position and heading of the turtle are not changed. If the given input is not a list or does not contain exactly two numeric elements, TOWARDS will throw an error.

*Top


Turtle State

These commands manipulate other state information.


SHOWTURTLE
ST

SHOWTURTLE shows the turtle if it is currently hidden. If the turtle is already shown, SHOWTURTLE has no effect.


HIDETURTLE
HT

HIDETURTLE hides the turtle if it is currently shown. If the turtle is already hidden, HIDETURTLE has no effect.


PENDOWN
PD

PENDOWN activates the drawing pen. Any subsequent move commands will cause the turtle to draw lines in the current pen color.


PENUP
PU

PENUP deactivates the drawing pen. The turtle will not perform any drawing during subsequent move commands.


PENERASE
PE

PENERASE sets the drawing pen to erase. Any subsequent move commands will cause the turtle to draw lines in the current background color.


SETPENCOLOR color
SETPC color

SETPENCOLOR sets the color of the drawing pen. The color may be in the format of a three-element list in which the elements are the RGB values, each between 0 and 255. It may also be a word specifying a color from the palette. If the input is a list with more or less than three elements or elements that are not integers between 0 and 255, or if the input is a word that does not correspond to an entry in the color palette, SETPENCOLOR throws an error.


SETBACKGROUND color
SETBG color

SETBACKGROUND sets the color of the background, also the color of the eraser. The color may be in the format of a three-element list in which the elements are the RGB values, each between 0 and 255. It may also be a word specifying a color from the palette. If the input is a list with more or less than three elements or elements that are not integers between 0 and 255, or if the input is a word that does not correspond to an entry in the color palette, SETBACKGROUND throws an error.


GETPENCOLOR
GETPC

GETPENCOLOR returns the color of the pen, in the form of a three-element list representing the RGB color. Each value in the list will be an integer between 0 and 255.


GETBACKGROUND
GETBG

GETBACKGROUND returns the color of the background, also the color of the eraser, in the form of a three-element list representing the RGB color. Each value in the list will be an integer between 0 and 255.

*Top


Color Palette Operations

These commands manipulate the color palette, which are values that can be used in SETPENCOLOR and SETBACKGROUND. The default color palette consists of standard system color numbers, and a selection of color names. Colors may be added to or removed from the palette. The default palette, set up when Turtle Tracks starts, is as follows:

System color numbers
Color number Color RGB Value
0 black [ 0 0 0 ]
1 blue [ 0 0 255 ]
2 green [ 0 255 0 ]
3 cyan [ 0 255 255 ]
4 red [ 255 0 0 ]
5 magenta [ 255 0 255 ]
6 yellow [ 255 255 0 ]
7 white [ 255 255 255 ]
Turtle Tracks color names
Color name RGB Value
"BLACK [ 0 0 0 ]
"BLUE [ 0 0 255 ]
"CYAN [ 0 255 255 ]
"DARKGRAY [ 64 64 64 ]
"GRAY [ 128 128 128 ]
"GREEN [ 0 255 0 ]
"LIGHTGRAY [ 192 192 192 ]
"MAGENTA [ 255 0 255 ]
"ORANGE [ 255 200 0 ]
"PINK [ 255 175 175 ]
"RED [ 255 0 0 ]
"WHITE [ 255 255 255 ]
"YELLOW [ 255 255 0 ]


SETPALETTE name rgblist

SETPALETTE associates the given color name with the given rgblist. It will then be possible to use the name to specify pen color or background color. If the first argument is not a word, or the second argument is not a list with three integer elements between 0 and 255, SETPALETTE throws an error.


UNSETPALETTE name

UNSETPALETTE disassociates the given color name, removing it from the palette. If no color with the given name exists, UNSETPALETTE does nothing. If the argument is not a word, UNSETPALETTE throws an error.


RESETPALETTE

RESETPALETTE sets the color palette to its default.


PALETTE name

PALETTE returns the rgblist associated with the given color name. If the specified color name is not found in the color palette, PALETTE returns the empty list. If the argument is not a word, PALETTE throws an error.


PALETTE? name
PALETTEP name

PALETTE? returns "TRUE if the given name is in the color palette, or "FALSE if not. If the argument is not a word, PALETTE? throws an error.

*Top


Daniel Azuma (dazuma@kagi.com)
Last updated 3 October 1999