[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Graphics

Berkeley Logo provides traditional Logo turtle graphics with one turtle. Multiple turtles, dynamic turtles, and collision detection are not supported. This is the most hardware-dependent part of Logo; some features may exist on some machines but not others. Nevertheless, the goal has been to make Logo programs as portable as possible, rather than to take fullest advantage of the capabilities of each machine. In particular, Logo attempts to scale the screen so that turtle coordinates [–100 –100] and [100 100] fit on the graphics window, and so that the aspect ratio is 1:1.

The center of the graphics window (which may or may not be the entire screen, depending on the machine used) is turtle location [0 0]. Positive X is to the right; positive Y is up. Headings (angles) are measured in degrees clockwise from the positive Y axis. (This differs from the common mathematical convention of measuring angles counterclockwise from the positive X axis.) The turtle is represented as an isoceles triangle; the actual turtle position is at the midpoint of the base (the short side). However, the turtle is drawn one step behind its actual position, so that the display of the base of the turtle's triangle does not obscure a line drawn perpendicular to it (as would happen after drawing a square).

Colors are, of course, hardware-dependent. However, Logo provides partial hardware independence by interpreting color numbers 0 through 7 uniformly on all computers:

 
0  black        1  blue         2  green        3  cyan
4  red          5  magenta      6  yellow       7 white

Where possible, Logo provides additional user-settable colors; how many are available depends on the hardware and operating system environment. If at least 16 colors are available, Logo tries to provide uniform initial settings for the colors 8-15:

 
 8  brown        9  tan         10  forest      11  aqua
12  salmon      13  purple      14  orange      15  grey

Logo begins with a black background and white pen.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Turtle Motion


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

forward

 
FORWARD dist
FD dist

moves the turtle forward, in the direction that it's facing, by the specified distance (measured in turtle steps).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

back

 
BACK dist
BK dist

moves the turtle backward, i.e., exactly opposite to the direction that it's facing, by the specified distance. (The heading of the turtle does not change.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

left

 
LEFT degrees
LT degrees

turns the turtle counterclockwise by the specified angle, measured in degrees (1/360 of a circle).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

right

 
RIGHT degrees
RT degrees

turns the turtle clockwise by the specified angle, measured in degrees (1/360 of a circle).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpos

 
SETPOS pos

moves the turtle to an absolute position in the graphics window. The input is a list of two numbers, the X and Y coordinates.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setxy

 
SETXY xcor ycor

moves the turtle to an absolute position in the graphics window. The two inputs are numbers, the X and Y coordinates.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setx

 
SETX xcor

moves the turtle horizontally from its old position to a new absolute horizontal coordinate. The input is the new X coordinate.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

sety

 
SETY ycor

moves the turtle vertically from its old position to a new absolute vertical coordinate. The input is the new Y coordinate.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setheading

 
SETHEADING degrees
SETH degrees

turns the turtle to a new absolute heading. The input is a number, the heading in degrees clockwise from the positive Y axis.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

home

 
HOME

moves the turtle to the center of the screen. Equivalent to SETPOS [0 0] SETHEADING 0.

See section setpos , See section setheading .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

arc

 
ARC angle radius

draws an arc of a circle, with the turtle at the center, with the specified radius, starting at the turtle's heading and extending clockwise through the specified angle. The turtle does not move.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Turtle Motion Queries


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pos

 
POS

outputs the turtle's current position, as a list of two numbers, the X and Y coordinates.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

xcor

 
XCOR						(library procedure)

outputs a number, the turtle's X coordinate.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ycor

 
YCOR						(library procedure)

outputs a number, the turtle's Y coordinate.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

heading

 
HEADING

outputs a number, the turtle's heading in degrees.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

towards

 
TOWARDS pos

outputs a number, the heading at which the turtle should be facing so that it would point from its current position to the position given as the input.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

scrunch

 
SCRUNCH

outputs a list containing two numbers, the X and Y scrunch factors, as used by SETSCRUNCH. (But note that SETSCRUNCH takes two numbers as inputs, not one list of numbers.)

See section setscrunch .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Turtle and Window Control


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

showturtle

 
SHOWTURTLE
ST

makes the turtle visible.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

hideturtle

 
HIDETURTLE
HT

makes the turtle invisible. It's a good idea to do this while you're in the middle of a complicated drawing, because hiding the turtle speeds up the drawing substantially.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

clean

 
CLEAN

erases all lines that the turtle has drawn on the graphics window. The turtle's state (position, heading, pen mode, etc.) is not changed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

clearscreen

 
CLEARSCREEN
CS

erases the graphics window and sends the turtle to its initial position and heading. Like HOME and CLEAN together.

See section home .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

wrap

 
WRAP

tells the turtle to enter wrap mode: From now on, if the turtle is asked to move past the boundary of the graphics window, it will "wrap around" and reappear at the opposite edge of the window. The top edge wraps to the bottom edge, while the left edge wraps to the right edge. (So the window is topologically equivalent to a torus.) This is the turtle's initial mode. Compare WINDOW and FENCE.

See section fence .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

window

 
WINDOW

tells the turtle to enter window mode: From now on, if the turtle is asked to move past the boundary of the graphics window, it will move offscreen. The visible graphics window is considered as just part of an infinite graphics plane; the turtle can be anywhere on the plane. (If you lose the turtle, HOME will bring it back to the center of the window.) Compare WRAP and FENCE.

See section home .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

fence

 
FENCE

tells the turtle to enter fence mode: From now on, if the turtle is asked to move past the boundary of the graphics window, it will move as far as it can and then stop at the edge with an "out of bounds" error message. Compare WRAP and WINDOW.

See section wrap .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

fill

 
FILL

fills in a region of the graphics window containing the turtle and bounded by lines that have been drawn earlier. This is not portable; it doesn't work for all machines, and may not work exactly the same way on different machines.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

filled

 
FILLED color instructions

runs the instructions, remembering all points visited by turtle motion commands, starting and ending with the turtle's initial position. Then draws (ignoring penmode) the resulting polygon, in the current pen color, filling the polygon with the given color, which can be a color number or an RGB list. The instruction list cannot include another FILLED invocation. (wxWidgets only)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

label

 
LABEL text

takes a word or list as input, and prints the input on the graphics window, starting at the turtle's position.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setlabelheight

 
SETLABELHEIGHT height

command (wxWidgets only). Takes a positive integer argument and tries to set the font size so that the character height (including descenders) is that many turtle steps. This will be different from the number of screen pixels if SETSCRUNCH has been used. Also, note that SETSCRUNCH changes the font size to try to preserve this height in turtle steps. Note that the query operation corresponding to this command is LABELSIZE, not LABELHEIGHT, because it tells you the width as well as the height of characters in the current font.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

textscreen

 
TEXTSCREEN
TS

rearranges the size and position of windows to maximize the space available in the text window (the window used for interaction with Logo). The details differ among machines. Compare SPLITSCREEN and FULLSCREEN.

See section splitscreen .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

fullscreen

 
FULLSCREEN
FS

rearranges the size and position of windows to maximize the space available in the graphics window. The details differ among machines. Compare SPLITSCREEN and TEXTSCREEN.

Since there must be a text window to allow printing (including the printing of the Logo prompt), Logo automatically switches from fullscreen to splitscreen whenever anything is printed.

In the DOS version, switching from fullscreen to splitscreen loses the part of the picture that's hidden by the text window. [This design decision follows from the scarcity of memory, so that the extra memory to remember an invisible part of a drawing seems too expensive.]


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

splitscreen

 
SPLITSCREEN
SS

rearranges the size and position of windows to allow some room for text interaction while also keeping most of the graphics window visible. The details differ among machines. Compare TEXTSCREEN and FULLSCREEN.

See section textscreen .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setscrunch

 
SETSCRUNCH xscale yscale

adjusts the aspect ratio and scaling of the graphics display. After this command is used, all further turtle motion will be adjusted by multiplying the horizontal and vertical extent of the motion by the two numbers given as inputs. For example, after the instruction SETSCRUNCH 2 1 motion at a heading of 45 degrees will move twice as far horizontally as vertically. If your squares don't come out square, try this. (Alternatively, you can deliberately misadjust the aspect ratio to draw an ellipse.)

For all modern computers, both scale factors are initially 1. For DOS machines, the scale factors are initially set according to what the hardware claims the aspect ratio is, but the hardware sometimes lies. For DOS, the values set by SETSCRUNCH are remembered in a file (called ‘scrunch.dat’) and are automatically put into effect when a Logo session begins.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

refresh

 
REFRESH

(command) tells Logo to remember the turtle's motions so that they can be used for high-resolution printing (wxWidgets) or to refresh the graphics window if it is moved, resized, or overlayed (non-wxWidgets). This is the default.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

norefresh

 
NOREFRESH

(command) tells Logo not to remember the turtle's motions, which may be useful to save time and memory if your program is interactive or animated, rather than drawing a static picture you'll want to print later (wxWidgets). In non-wxWidgets versions, using NOREFRESH may prevent Logo from restoring the graphics image after the window is moved, resized, or overlayed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 Turtle and Window Queries


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

shownp

 
SHOWNP
SHOWN?

outputs TRUE if the turtle is shown (visible), FALSE if the turtle is hidden. See SHOWTURTLE and HIDETURTLE.

See section showturtle , hideturtle .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

screenmode

 
SCREENMODE

outputs the word TEXTSCREEN, SPLITSCREEN, or FULLSCREEN depending on the current screen mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

turtlemode

 
TURTLEMODE

outputs the word WRAP, FENCE, or WINDOW depending on the current turtle mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

labelsize

 
LABELSIZE

(wxWidgets only) outputs a list of two positive integers, the width and height of characters displayed by LABEL measured in turtle steps (which will be different from screen pixels if SETSCRUNCH has been used). There is no SETLABELSIZE because the width and height of a font are not separately controllable, so the inverse of this operation is SETLABELHEIGHT, which takes just one number for the desired height.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Pen and Background Control

The turtle carries a pen that can draw pictures. At any time the pen can be UP (in which case moving the turtle does not change what's on the graphics screen) or DOWN (in which case the turtle leaves a trace). If the pen is down, it can operate in one of three modes: PAINT (so that it draws lines when the turtle moves), ERASE (so that it erases any lines that might have been drawn on or through that path earlier), or REVERSE (so that it inverts the status of each point along the turtle's path).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pendown

 
PENDOWN
PD

sets the pen's position to DOWN, without changing its mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

penup

 
PENUP
PU

sets the pen's position to UP, without changing its mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

penpaint

 
PENPAINT
PPT

sets the pen's position to DOWN and mode to PAINT.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

penerase

 
PENERASE
PE

sets the pen's position to DOWN and mode to ERASE.

See section erase .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

penreverse

 
PENREVERSE
PX

sets the pen's position to DOWN and mode to REVERSE. (This may interact in system-dependent ways with use of color.)

See section reverse .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpencolor

 
SETPENCOLOR colornumber.or.rgblist
SETPC colornumber.or.rgblist

sets the pen color to the given number, which must be a nonnegative integer. There are initial assignments for the first 16 colors:

 
 0  black	 1  blue	 2  green	 3  cyan
 4  red		 5  magenta	 6  yellow	 7 white
 8  brown	 9  tan		10  forest	11  aqua
12  salmon	13  purple	14  orange	15  grey

but other colors can be assigned to numbers by the PALETTE command. Alternatively, sets the pen color to the given RGB values (a list of three nonnegative numbers less than 100 specifying the percent saturation of red, green, and blue in the desired color).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpalette

 
SETPALETTE colornumber rgblist

sets the actual color corresponding to a given number, if allowed by the hardware and operating system. Colornumber must be an integer greater than or equal to 8. (Logo tries to keep the first 8 colors constant.) The second input is a list of three nonnegative numbers less than 100 specifying the percent saturation of red, green, and blue in the desired color.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpensize

 
SETPENSIZE size

sets the thickness of the pen. The input is either a single positive integer or a list of two positive integers (for horizontal and vertical thickness). Some versions pay no attention to the second number, but always have a square pen.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpenpattern

 
SETPENPATTERN pattern

sets hardware-dependent pen characteristics. This command is not guaranteed compatible between implementations on different machines.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setpen

 
SETPEN list					(library procedure)

sets the pen's position, mode, thickness, and hardware-dependent characteristics according to the information in the input list, which should be taken from an earlier invocation of PEN.

See section pen .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setbackground

 
SETBACKGROUND colornumber.or.rgblist
SETBG colornumber.or.rgblist

set the screen background color by slot number or RGB values. See SETPENCOLOR for details.

See section setpencolor .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6 Pen Queries


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pendownp

 
PENDOWNP
PENDOWN?

outputs TRUE if the pen is down, FALSE if it's up.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

penmode

 
PENMODE

outputs one of the words PAINT, ERASE, or REVERSE according to the current pen mode.

See section erase , reverse .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pencolor

 
PENCOLOR
PC

outputs a color number, a nonnegative integer that is associated with a particular color, or a list of RGB values if such a list was used as the most recent input to SETPENCOLOR. There are initial assignments for the first 16 colors:

 
 0  black        1  blue         2  green        3  cyan
 4  red          5  magenta      6  yellow       7 white
 8  brown        9  tan         10  forest      11  aqua
12  salmon      13  purple      14  orange      15  grey

but other colors can be assigned to numbers by the PALETTE command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

palette

 
PALETTE colornumber

outputs a list of three nonnegative numbers less than 100 specifying the percent saturation of red, green, and blue in the color associated with the given number.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pensize

 
PENSIZE

outputs a list of two positive integers, specifying the horizontal and vertical thickness of the turtle pen. (In some implementations, including wxWidgets, the two numbers are always equal.)

 
PENPATTERN

outputs system-specific pen information.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

pen

 
PEN						(library procedure)

outputs a list containing the pen's position, mode, thickness, and hardware-specific characteristics, for use by SETPEN.

See section setpen .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

background

 
BACKGROUND
BG

outputs the graphics background color, either as a slot number or as an RGB list, whichever way it was set. (See PENCOLOR.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7 Saving and Loading Pictures


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

savepict

 
SAVEPICT filename

command. Writes a file with the specified name containing the state of the graphics window, including any nonstandard color palette settings, in Logo's internal format. This picture can be restored to the screen using LOADPICT. The format is not portable between platforms, nor is it readable by other programs. epspict to export Logo graphics for other programs.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

loadpict

 
LOADPICT filename

command. Reads the specified file, which must have been written by a SAVEPICT command, and restores the graphics window and color palette settings to the values stored in the file. Any drawing previously on the screen is cleared.

See section savepict .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

epspict

 
EPSPICT filename

command. Writes a file with the specified name, containing an Encapsulated Postscript (EPS) representation of the state of the graphics window. This file can be imported into other programs that understand EPS format. Restrictions: the drawing cannot use FILL, PENERASE, or PENREVERSE; any such instructions will be ignored in the translation to Postscript form.

See section fill , See section penerase , See section penreverse .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8 Mouse Queries


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

mousepos

 
MOUSEPOS

outputs the coordinates of the mouse, provided that it's within the graphics window, in turtle coordinates. If the mouse is outside the graphics window, then the last position within the window is returned. Exception: If a mouse button is pressed within the graphics window and held while the mouse is dragged outside the window, the mouse's position is returned as if the window were big enough to include it.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

clickpos

 
CLICKPOS

outputs the coordinates that the mouse was at when a mouse button was most recently pushed, provided that that position was within the graphics window, in turtle coordinates. (wxWidgets only)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

buttonp

 
BUTTONP
BUTTON?

outputs TRUE if a mouse button is down and the mouse is over the graphics window. Once the button is down, BUTTONP remains true until the button is released, even if the mouse is dragged out of the graphics window.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

button

 
BUTTON

outputs 0 if no mouse button has been pushed inside the Logo window since the last call to BUTTON. Otherwise, it outputs an integer between 1 and 3 indicating which button was most recently pressed. Ordinarily 1 means left, 2 means right, and 3 means center, but operating systems may reconfigure these.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Brian Harvey on September, 3 2008 using texi2html 1.78.