TG is a Turtle Graphics program which provides a
command line interface to a Java-based implementation
of a subset of Berkeley Logo.
Most of this Help message has been taken from Brian
Harvey's documentation of Berkeley Logo, from Computer
Science Logo Style, Brian Harvey, The MIT Press, 1997.
Brian has kindly provided Berkeley Logo under the GNU
General Public License. Thank you, Brian!
The center of the graphics window 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 a hexagon with head, legs
and a tail; the actual turtle position is in the
middle of the turtle.
AND trueFalse1 trueFalse2
Outputs true if trueFalse1 AND trueFalse2 are
true, otherwise it outputs false.
Example:
IF AND EQUAL? XCOR 0 EQUAL? YCOR 0 PRINTLN "Home
BF word-or-sentence
BUTFIRST word-or-sentence
If the input is a word, all characters except its
first are output. If the input is a sentence, all
words except the first are output.
BK number
BACK number
Moves the turtle backward, i.e., exactly
opposite to the direction that it's facing,
by the specified number of turtle steps.
Example: BACK 150
BL word-or-sentence
BUTLAST word-or-sentence
If the input is a word, all characters except its
last are output. If the input is a sentence, all
words except the last one are output.
CG
CLEAN
Erases everything that the turtle has drawn in the
graphics window. The turtle's state (position,
heading, pen color, etc.) is not changed.
COS number
Outputs the cosine of number, which is degrees.
COUNT word-or-sentence
If the input is a word, the number of characters
in it is output. If the input is a sentence, the
number of words in it is output.
CT
CLEARTEXT
Erases all of the text in the terminal window.
DIFFERENCE number1 number2
Outputs the result of subtracting number2 from
number1.
Example: DIFFERENCE 15 7
EQUAL? value1 value2
EQUALP value1 value2
If value1 is equal to value2, true is output;
otherwise false is output.
Example: EQUAL? MOUSEX 0
EMPTY? word-or-sentence
EMPTYP word-or-sentence
Outputs true if its input is a word that has no
characters in it, otherwise false. Outputs true
if its input is a sentence that has no words in
it, otherwise false.
FD number
FORWARD number
Moves the turtle forward, in the direction it is
facing, by the specified number of turtle steps.
Example: FORWARD 100
FILL
Whatever color is under the turtle is changed to
the turtle's color, and this process is repeated
in an outward manner for all pixels that are
neighbors and match the original color.
FIRST word-or-sentence
If the input is a word, its first character is
output. If the input is a sentence, its first
word is output.
GREATER? value1 value2
GREATERP value1 value2
If value1 is greater than value2, true is output;
otherwise false is output.
Example: GREATER? MOUSEX 0
HEADING
Outputs the turtle's heading (degrees).
Example: PRINTLN HEADING
HT
HIDETURTLE
Makes the turtle invisible.
HOME
Moves the turtle to the center of the graphics
window, i.e., coordinates 0,0.
IF boolean [ instructions ]
The instructions enclosed in the square brackets
are performed if the boolean value is true,
nothing is done if it's false. The boolean
value must be either true or false.
Example: IF LESS? :INPUT 0 [ STOP ]
ITEM number word-or-sentence
Outputs the number-th element of its second input.
If its second input is a word, it outputs a word
consisting on the number-th character. If its
second input is a sentence, it outputs the
number-th word of it.
KEYPRESSED
When a keyboard key is pressed, TG receives an event.
If the key is one that TG is interested in, a user-
defined procedure with the name KEYPRESSED (expecting
one input) is invoked if it has been defined.
Example: TO keyPressed :keyNum
PRINTLN SENTENCE "keyPressed= :keyNum
END
Key numbers that TG passes on are:
Number Key
------ -------
10 Enter
32 Space
128 Down-Arrow
129 Left-Arrow
130 Right-Arrow
131 Up-Arrow
LABEL word
LABEL sentence
The text representing LABEL's input is drawn in
the graphics window.
LAST word-or-sentence
If the input is a word, its last character is
output. If the input is a sentence, its last
word is output.
LESS? value1 value2
LESSP value1 value2
If value1 is less than value2, true is output;
otherwise false is output.
Example: LESS? MOUSEX 0
LT number
LEFT number
Turns the turtle counterclockwise by the
specified angle measured by a number of degrees
(1/360 of a circle).
Example: LEFT 180
MAKE name value
Creates a variable named name if it doesn't
already exist. The contents of the variable
is set to value.
Example: MAKE "WHITE 7
MEMBER? character word
MEMBER? word sentence
MEMBERP character word
MEMBERP word sentence
Outputs true if its first input is in its second
input, otherwise it outputs false.
MINUS number
Outputs the negative of number.
Example: MINUS 10
MOUSECLICK
When a mouse-click (left button) is received by
TG, it invokes a user-defined procedure with the
name MOUSECLICK, if one has been defined.
Example: TO mouseclick
PRINTLN "mouseclick
END
MOUSEX
Outputs the X-coordinate where the mouse was
when it was last clicked.
MOUSEY
Outputs the Y-coordinate where the mouse was
when it was last clicked.
NOT trueFalse
Outputs false if trueFalse is true, else false.
OR trueFalse1 trueFalse2
Outputs true if trueFalse1 OR trueFalse2 is true,
otherwise it outputs false.
Example:
IF OR EQUAL? XCOR 0 EQUAL? YCOR 0 PRINTLN [On Axis]
OUTPUT value
The current invocation of the procedure in which
OUTPUT exists is teminated and value is output.
Example: TO randomColor
OUTPUT RANDOM 16
END
PD
PENDOWN
Puts the turtle's pen down so that it leaves a
trace when it moves.
PP
PRINTPROCS
Displays the names and inputs of all the user-
defined procedures in the terminal window.
PRINTLN word
PRINTLN sentence
The text representing PRINTLN's input is drawn
in the terminal window.
PRODUCT number1 number2
Outputs the result of multiplying number1 by
number2.
Example: PRODUCT 64 8
PT
PRINTTEXT name
Displays the source code representation of
the user-defined procedure named name in the
terminal window.
PU
PENUP
Lifts the turtle's pen up so that it leaves no
trace when it moves.
QUOTIENT number1 number2
Outputs the result of dividing number1 by number2.
Example: QUOTIENT 16384 4096
RANDOM number
Outputs some integer greater-than or equal-to
zero AND less-than number.
Example: RANDOM 16
REMAINDER number1 number2
Output the remainder left after dividing number1
by number2.
Example: REMAINDER 1234 10
REPEAT number [ instructions ]
Repeats the instructions enclosed in the square
brackets the specified number of times.
Example: REPEAT 4 [ FD 100 RT 90 ]
ROUND number
Outputs the closest integer to number.
Example: ROUND 22.45
RT number
RIGHT number
Turns the turtle clockwise by the specified angle,
measured in degrees (1/360 of a circle).
Example: RIGHT 90
SENTENCE word word
SENTENCE word sentence
SENTENCE sentence word
SENTENCE sentence sentence
Outputs a sentence consisting of its first input
concatenated with its second input.
SETC number
SETPC number
SETPENCOLOR number
Sets the turtle's color - the color of its pen.
Color is expressed as a number. The available
colors are:
Number
Color Number Color
------ -------
------ -------
0
black
8 brown
1
blue
9 tan
2
green
10 forest
3
cyan
11 aqua
4
red
12 salmon
5
magenta 13 purple
6
yellow 14
orange
7
white
15 grey
Example: SETC 10
SETH number
SETHEADING number
Turns the turtle to a new absolute heading.
The input, number, is the heading in degrees
clockwise from the positive Y axis, i.e.,
0 is due North (up),
90 is due East (right),
180 is due South (down), and
270 is due West (left).
Example: SETH 90
SETLH number
SETLABELHEIGHT number
The height of characters drawn with the LABEL
procedure is set to the input.
Example: SETLABELHEIGHT 24
SETPS number
SETPENSIZE number
Sets the width of the turtle's pen, which
determines the thickness of the trace it leaves,
the line it draws.
Example: SETPENSIZE 5
SETX number
Moves the turtle horizontally to the specified
absolute window position.
Example: SETX 100
SETXY number1 number2
Moves the turtle to an absolute window position,
which is two numbers: the new horizontal (X) and
vertical (Y) coordinates.
Example: SETXY 50 -30
SETY number
Moves the turtle vertically to the specified
absolute window position.
Example: SETY 100
SIN number
Outputs the sine of number which is in degrees.
Example: SIN 45
SQRT number
Outputs the square root of number.
Example: SQRT 64
ST
SHOWTURTLE
Makes the turtle visible.
STOP
The current invocation of the procedure in which
STOP exists terminates.
Example: IF EQUAL? :input 0 [STOP]
SUM number1 number2
Outputs the result of adding number1 and number2.
Example: SUM 123 456
WAIT number
Execution of the program is suspended for number
of milliseconds (1/1000 of a second).
WORD word word
Outputs a word consisting of its first input
concatenated with its second input.
XCOR
Outputs the turtle's X coordinate.
Example: MAKE "curX XCOR
YCOR
Outputs the turtle's Y coordinate.
Example: LABEL YCOR