Try looking at the code in some of the examples, and keep this reference handy.
Drawing units are 100 per inch, based in the lower left corner of the window (the origin).
They can be given as whole numbers or decimal numbers.
Sometimes we refer to x y coordinate pairs to identify an exact point in the picture.
For example, 300 100 identifies the point that is 300 units to the right and 100 units
above the lower left corner of the window.
Angles are always in degrees. 0 degrees is straight up. 90 is due right. Values may
be whole numbers or decimal numbers.
Commands are either a single word such as CLEAR or a word followed by one or more values
such as FD 300 or SAYC "Hello".
It is also possible for a value to be another command, like this: FD (RANDOM 100).
Words and values must always be separated by space. Parentheses and semicolons
may be used too for readability but are optional and ignored. Commands can be upper or lower case. A command
can occupy one or more lines, or several commands can be together on one line.
Variables are created and given a value using the SET command.
Variable names should be written beginning with a colon like this :total
Quoting: All alphanumeric values, including color names and file names, must be enclosed
in "double quotes". Commands, procedure names, and variable names are never quoted. Quoted text cannot run
over onto a second line.
Comments begin with //. Comments may occupy an entire line or begin to the right of commands.
|PU ||Pen up.|
|PD ||Pen down.|
|FD n ||Move forward n units. Example: fd 200|
|BK n ||Move backward n units. Example: bk 30.5|
|RT d ||Right turn d degrees. Example: rt 45|
|LT d ||Left turn d degrees. Example: lt 90|
|MOVETO x y ||Move turtle to location x y. Example: moveto 300 170 .
If pen is down a line will be drawn. TURTLEDIR is updated based on movement.
|CLEAR ||Clear screen.|
|CLEANSLATE ||Clear screen and reset everything to defaults.|
|CIRCLE n ||Draw a circle with size (radius) n units. Example: circle 40|
|ELLIPSE n m ||Draw an ellipse (oval). Example: ellipse 100 30 |
|POLYGON n s d ||Draw a regular polygon with size (radius) n units, with s sides,
and rotated d degrees. Example: polygon 100 6 0|
|RECTANGLE x y ||Draw a rectangle with lower-left at current location and
upper right at x y. Example: rectangle 300 320|
|FILLSHAPE ||Fill the most recently drawn shape with color.|
Colors can be given as a quoted word such as "black", "white" or "red".
Color can also be given as RANDOMCOLOR, or
as 3 numbers between 0 and 100 for red, green, and blue components.
Here's the complete list of color names:
white black yellow yellow2 dullyellow yelloworange
red magenta tan1 tan2 coral claret pink
brightgreen green teal drabgreen kelleygreen yellowgreen limegreen
brightblue blue skyblue darkblue oceanblue
purple lightpurple lavender powderblue powderblue2
orange redorange lightorange lightgray
|LOGO LINECOLOR color ||Set color as the current line color.
Example: logo linecolor "red"|
|LOGO FILLCOLOR color ||Set color as the current fillshape color.
Example: logo fillcolor "blue"|
|LOGO BACKCOLOR color ||Set color as the background color, and clear the screen.
Example: logo backcolor 0 30 58|
|RANDOMCOLOR ||A randomly selected color. Example: logo linecolor randomcolor|
Special locations in the picture
|MIDDLE ||The middle of the screen. Example: moveto middle|
|CENTER ||The horizontal center of the screen. Example: moveto center 100|
|WINHIGH ||The top of the window. Example: moveto 100 winhigh|
|WINWIDE ||The right size of the window. Example: moveto winwide 25 |
|0 ||The bottom of the window is 0. So is the left side of the window.|
|\n may be used in text to go to the next line.|
|SAY t ||Display text t. Examples: say "hello" or say linecolor|
|SAYC t ||Display text t, centered at current location. sayc "Hello"|
|PRINT t ||Write text t to the terminal (standard output). print turtlepos|
|PRINTF fmt a1 .. an ||Write a1 .. an to terminal. fmt is a printf(3) format string
with %s only. Example: printf "x = %s; y=%s" :x :y |
|LOGO TEXTSIZE p ||Set the text size to p points (default is 10).|
|CONCAT n a1 .. an ||Combine or concatenate n args. Example: concat 3 "You have " :np " points"|
|SET v = x ||Set variable V to value X. |
|SETIFNOTGIVEN v = x ||(Advanced) Like SET, but only takes effect if V was never set. Useful when
passing values in from the command line.|
|IF a = b [ commands1 ] |
ELSEIF c = d [ commands2 ]
ELSE [ commands3 ]
|If statement. a and b can be values, variables, or
You can use any of these comparison operators: = (equal to)
!= (not equal), < ≥ <= >=.
Furthermore, two or more comparisons can be connected using
AND or OR (but not a mixture of the two).
commands may be one or more commands and may occupy one line or
be spread over several lines. The square [brackets] are always required.
ELSEIF and ELSE are optional.
|REPEAT n [ |
|Loop statement. Run commands repeatedly n times.
The square [brackets] are always required.|
|REPEAT UNTILBREAK [ |
|Same as REPEAT but runs until a BREAK command occurs.
If you have a runaway loop click in the window then do a Ctrl-C
(hold the Ctrl key down and touch the C key).
|BREAK ||Jump out of the current loop. Example: if :count > 10 [ break ]|
|CONTINUE ||Jump to the top of the current loop and begin the next iteration.|
|INCLUDE filename ||Do an in-line include of another code file. Useful in sharing
common procedures between several programs. Example: include "star1"|
|TO procname args ||Begin a procedure called procname. If any values are to
be passed to the procedure, these are given as args.
Here's an example (procedure star1)
|RETURN x ||Used within a TO procedure. Control jumps back to the
originating code, with value x|
|END ||Marks the end of a TO procedure. Must be used with every TO procedure.|
|TRUE ||Same as 1|
|FALSE ||Same as 0|
Arithmetic & numbers
|CALC a + b ||Perform arithmetic on a and b. a and b
must represent numeric quantities. You can do one of the following:|
Advanced operators include
div (integer division), mod (integer modulo), and
fmod (floating point modulo).
|INCR v BY x ||Increase/increment the value in variable v by x|
|DECR v BY x ||Decrease/decrement the value in variable v by x|
|RANDOM m ||Return a random decimal number between 0 and m|
|IRANDOM m ||Return a random integer (counting number) between 0 and m|
|ABS x ||Return the absolute value of x|
|DISTANCETO x y ||Return the distance between current location and x y,
in draw units.|
|INRANGE x low hi ||Return TRUE if x >= low and x <= hi|
|SINE x ||Return a sine function of x.
The function is scaled so that one complete sine wave cycle occurs
as x increases from 0 to 400. The sine wave amplitude ranges
from +100 units to -100 units.
|LOGO ANIMATION ||Use this at the beginning of any program that is a free-running
animation, such as the bounce example. Basically this turns
off the record-keeping and overhead necessary for printing the picture.
|WAIT t ||Pause or delay for t hundredths of a second. Example: wait 100|
|ERASESHAPE ||Erase the most recently drawn line shape by redrawing it using BACKCOLOR|
|KEYPRESS ||Return TRUE if any key / mouse button has been pressed, or a button in a
MESSAGE window has been pressed. Otherwise it immediately returns FALSE.
Often used to stop animations.|
|Ctrl-C ||To stop a runaway animation, click on the picture, then hold the Ctrl
key down and press the C key.|
Getting user responses
|Longer messages and prompts can use \n to move on to the next line.|
|GETKEY ||Wait for user to click with mouse on graphic area, press a keyboard key,
or click on a button in a MESSAGE window. |
|WHICHKEY ||Used after GETKEY or KEYPRESS. Returns left if the left button was
pressed, or right or middle. If a keyboard key was pressed the
key's letter is returned. If a button was pressed in a MESSAGE window,
the button label is returned.|
|WHERECLICK ||Used after GETKEY or KEYPRESS. Returns the x y location where the mouse
pointer was, when the key/button press occured.|
|MESSAGE txt btns ||Create a message window. Display message txt, and buttons btns.
After creating the message window it returns immediately.
message "Spinner" "Stop"
|CLEARMESSAGE ||Clear the current message window if any.|
|SAMEMESSAGE ||Display the most recent message window again.|
|BUTTONCHOICE txt btns ||Create a message window. Display message txt, and buttons btns.
Buttons are specified using a bar separator like this: "red|green|blue".
Wait for user to make a selection, then return the text of the chosen button.
set ans = buttonchoice "Select one:" "25|50|100"
|COLORCHOICE txt ||Create a message window. Display message txt, and a set of
predefined color selection buttons.
Wait for user to make a selection, then return the selected color name.
set c = colorchoice "Select a color"
|TYPEIN txt btns ||Create a message window. Display message txt, a key input area, and any
buttons btns. If you don't want any buttons, use "".
Wait for user to type in and press Enter (or click on a button).
Return user's input, or button label.
set name = typein "Enter your name" "Cancel"
|FILEPICK txt dir pat ||Create a message window. Display message txt and a select box of files
located in directory dir that match pattern pat (use * for all).
Returns the selected filename, or the word "Cancel".
set file = filepick "Select a file" "./ptsfiles" "*.pts"
|PRINTPICTURE ||Begin the dialog sequence where user can opt to print current picture or
create a GIF image.|
Working with point lists (advanced)
|POINTLIST STARTCAPTURE ||Start capturing points. Returns the pointlist number.|
|POINTLIST ENDCAPTURE ||Stop capturing points. Completed pointlist is now the
|POINTLIST SUSPEND ||Temporarily suspend the capturing of points.|
|POINTLIST RESUME ||Resume capturing of points after a POINTLIST SUSPEND.|
|POINTLIST SIZE ||Return the number of points in the current point list.|
|POINTLIST SAVEFILE f ||Save the current pointlist to file f|
|POINTLIST CLEARALL ||Clear all pointlists.|
|POINTLIST DRAW ||Draw the current pointlist verbatim.|
|POINTLIST RENDER x y s ||Draw the current pointlist at location x y units, scaled
by s. If s < 1.0 the result will be smaller than original;
if s > 1.0 result will be larger.|
|POINTLIST CURRENT ||Return the pointlist number of the current point list.|
|POINT n ||Return the x y location of the nth point
in the pointlist (first = 1)|
|POINTX n ||Return the x location of the nth point in
|POINTY n ||Return the y location of the nth point in
|LOGO SETPOINTLIST g ||Make pointlist g the current point list. g is a pointlist
number of a pointlist that has already been captured. In most situations
this doesn't need to be used, since the most recently captured pointlist is
the current one by default.|
The following commands generate new points and must be
within a STARTCAPTURE / ENDCAPTURE construct:
|POINTLIST LOADFILE f ||Read all points from the pointlist file f |
|POINTLIST DOTFILL h ||For each line segment in current pointlist compute a series of points
spaced h units apart, for dot animations, etc.|
|POINTLIST CURVEFILL ||For each continuous set of line segments in the current pointlist, compute
a smooth curve that passes through each point.|
|LOGO LINECOLOR c ||Set c as the current line color. Example: logo linecolor "red"|
|LOGO FILLCOLOR c ||Set c as the current fillshape color. logo fillcolor "blue"|
|LOGO BACKCOLOR c ||Set c as the background color. logo backcolor 0 30 58|
|LOGO TURTLEDIR d ||Set the current turtle direction to d in degrees|
|LOGO LINETHICK t ||Set the thickness for drawn lines to t. Default t = 1.|
|LOGO TURTLE t ||Set turtle's location, direction, line color & thickness, and pen status.
Allows you to "checkpoint" the turtle then come back to it later exactly as it was,
or to have several "virtual" turtles. Example: |
set t1 = turtle
logo turtle = :t1
|LOGO TEXTSIZE p ||Set the text size to p points (default is 10).|
|LOGO WRAPEDGES ||Use this at the beginning of any program where you want lines
that stray out of the drawing area to be "wrapped around" so that they
continue to be visible. Only lines drawn using FD or BK can be
controlled this way.|
|LOGO CIRCPOINTS n ||Draw circles and ellipses using n points/sides.|
|LOGO CIRCROTATE d ||Display all drawn ellipses as rotated by d degrees.|
|LOGO CIRCARC a1 a2 ||Display only the portion from a1 degrees to a2 degrees of
drawn circles, ellipses, and polygons.|
|LOGO CIRCSPIRAL n cr ||Display all drawn circles as spirals of n revolutions, creeping
outward by cr units.|
|LOGO ANIMATION ||See animation, above.|
|LOGO SETPOINTLIST g ||See Working with pointlists, above.|
Getting current turtle info
|TURTLEPOS ||The x y location of the turtle. Example: set pos = turtlepos|
|TURTLEX ||The x location of the turtle. |
|TURTLEY ||The y location of the turtle.|
|TURTLEDIR ||The direction (in degrees) of the turtle.|
|TURTLEPEN ||The pen status of the turtle, either up or down|
|TURTLE ||Used with LOGO TURTLE (above).|
|LINECOLOR ||The current line color.|
|FILLCOLOR ||The current fillshape color.|
|BACKCOLOR ||The current background color.|