Programming Geometry With Turtle Graphics   Tslow.GIF (2091 bytes)   Directions    

Your browser does not support java

 

 

  Hide   Walls  Examples

   

For directions and specific explanations, see the following: Turtle Applet Directons and Explanations

Link to Poseidon Software and Invention Home Page

Brief Command and Variable summary.

Turtle Commands Syntax Function
CLS One word command Clears the screen of drawn graphics
RESET One word command Resets the modifiable variables (not a generic turtle command, but a good practice to put this at the start)
PENUP One word command Lifts the pen, so moving will not draw a line
PENDOWN One word command Readys pen to draw, so moving will draw a line
FORWARD Optional number can follow.  If no number follows, the value in LENGTH is used for distance of move.  Moves the turtle in the direction facing.
REPEAT One word command Repeats the whole script from the start.
COLOR Specific color follows or RANDOM which selects a color Sets color of pen
LEFT Number follows indicating degress to turn left. Turns turtle left specific number of degrees.
RIGHT Number follows indicating degrees to turn right. Turns turtle right specific number of degrees.
ERASE One word command Erases last entered command (not a generic turtle command. Use when entering commands one at a time and a mistake is made)
Variables Syntax (all variables have same syntax) Funtions
X = sign followed by number or RANDOM X coordinate of the turtle
Y see above Y coordinate of the turtle
ANGLE see above Positions the direction of the turtle
LENGTH see above Indicates length of the next move FORWARD if the FORWARD command does not specify a length
I see above Variable used to store a number
J see above Variable used to store a number
K see above Variable used to store a number
DELTALENGTH see above Indicates how much LENGTH variable will be changed after a move FORWARD
DELTAANGLE see above Indicates how much ANGLE variable will be changed after a move FORWARD
LOWRANDOM see above Used to determine low bounds of number that RANDOM generates
HIGHRANDOM see above Used to determine high bounds of number that RANDOM generatesr
XMIN Read only variable (used only in conditionals) Represents minimum x coordinate of applet
XMAX Read only variable (used only in conditionals) Represents maximum x coordinate of applet
YMIN Read only variable (used only in conditionals) Represents minimum y coordinate of applet
YMAX Read only variable (used only in conditionals) Represents maximum y coordinate of applet
Flow Syntax Function
DO One word Indicates beginning of a DO UNTIL loop.
UNTIL Followed by condition that will end the DO loop.  Variable (or number) then the Conditional followed by a variable (or number).  Eg. UNTIL I >= 10. or UNTIL ANGLE < 360.   Parentheses are optional, eg UNTIL ( I > 10 ) Indicates the end of a DO UNTIL loop.  When the UNTIL statement is reached, the condition is evaluated and if it passes evaluation, the next line is read, otherwise flow goes back to the DO statement preceeding the UNTIL.  These loops may be nested.
BREAK One word Breaks out of a DO UNTIL loop. Instruction processing continues after the UNTIL statement of a DO UNTIL loop.
IF Followed by condition that will to test.  Variable (or number), then the Conditional followed by a variable (or number). Eg. IF X >= 200, or IF DELTALENGTH > 50. Parentheses are optional, eg IF ( Y < 20 ) Indicates the beginning of an IF ENDIF block of instructions.  If the condition passes evaluation, then the instructions between the IF and ENDIF statement are carried out.   Otherwise nothing happens until the ENDIF statement is reached.
ENDIF One word. Indicates the end of the IF block of instructions
Conditionals Syntax (occurs in IF or UNTIL statements) Functon
Is equal to ==   eg. IF X == 5 or UNTIL x == 5 Evaluates variable before and after for equality
Is greater than >    eg. IF ANGLE > 360 or UNTIL ANGLE > 360 Tests if variable before is greater than variable after
Is less than <    eg. IF DELTALENGTH < -50 or UNTIL DELTALENGTH < -50 Tests if variable before is less than variable (or number) after
Is greater than or equal to >=   eg. IF 5 >= DELTAANGLE or UNTIL 5 >= DELTAANGLE Tests if variable before is greater than or equal to variable (or number) after
Is less than or equal to <=   eg. IF J <= 10 or UNTIL J <= 10 Tests if variable before is less than or equal to variable (or number) after
Operations Syntax (operates on variables listed above) Function
Sets a variable =    eg. X = 5 Sets a variable to a number
Adds to a variable +=   eg. ANGLE += 10 Adds variable (or number) following to variable before
Multiplies a variable *=    eg. LENGTH *= 5 Multiplies variable (or number) following to variable before
Divides a variable /=    eg. LENGTH -= 5 Divides variable (or number) following from variable before
Subtracts from a variable -=    eg. LENGTH -= 5 Subtracts variable (or number) following to variable before
Increments variable ++   eg.. ANGLE++ Adds 1 to preceeding variable
Decrements variable --     eg.  I-- Subtracts 1 from preceeding variable
More Commands Syntax Function
DRAW Followed by 2 arguments with parentheses with comma's or whitespace seperating arguments eg. DRAW(10,10) Draws a line from the current position to the (X,Y) coordinate given.
SETXY Followed by 2 arguments with parentheses with comma's or whitespace seperating arguments eg. SETXY(10,10) Positions the turtle at the (X,U) coordinate given.
SETRANDOM Followed by 2 arguments with parentheses with comma's or whitespace seperating arguments eg. SETRANDOM(1,10) Sets the LOWRANDOM and HIGHRANDOM values to determine the range of a number when RANDOM is used
DOT Followed by 2 arguments with parentheses with comma's or whitespace seperating arguments eg. DOT(10,10) Draws a dot on the screen 1pixel in size at the given X,Y coordinates

After the above commands have been investigated you can use JavaScript or VBScript to control the turtle.  Also to program some of the recursive functions illustrated in 'Turtle Geometry' you will need a robust scripting language like JavaScript or VBScript.  The following page has some examples of using JavaScript to control the Turtle Applet TurtleScript

Date last updated 10/11/98

Copyright 1998 Poseidon Software and Invention