TURTLE GRAPHICS - TURTLE.exe

PJR Millican 2003 Version 7

A PROGRAM is a set of instructions or commands to be performed.

Syntax: The RULES and structure to write the instructions. This include punctuation. (Parentheses, periods, Semi-colons, spacing, etc)

MOST lines have a Semi-colon ; at the end of the line.

VAR is the syntax key word needed to identify a VARIABLE. A Variable is used to represent a number or value. Turtle Graphics only has a Variable Type of INTEGER. (Other programming languages have other variable types such as REAL, STRING, CHARACTER, ARRAY or TABLE, BOOLEAN). Variables “declared” at the start of the program are GLOBAL and can be used anywhere in the program.

A PROCEDURE is a set of instructions in a program that can be used over and over again. (It is often called a Sub-Routine).

Procedures may also have variables but they are often referred to as Arguments. Arguments and Variables inside a procedure are LOCAL to the procedure. (ie not shared).

Procedures (if you have them) are placed at the top of the program before the main key word: BEGIN;

PROGRAM programname;

The programname can only be letters, numbers, or underscore _

(No, special characters or spaces)

VAR varname: INTEGER;

{Notice the COLON : after the variable name. Variable Names can only be letters, numbers and underscores}


BEGIN; All programs start with a BEGIN;

{COMMENTS or REMARKS go inside Braces};

{Key Words and Commands ArE Not CasE Sensitive}

{Commands can be all on one line or indented for HUMAN readability.

The Computer does not care how the commands “LOOK”}

END. All programs end with an END.

PAUSE(#); Cause the program to PAUSE or wait:

Replace the (#) with a Number: (1000) = 1 second

MOVEMENT COMMANDS:

Forward(#); Move Forward # units. May use FD(#);

Back(#); Move Backward # units. May use BK(#);

Right(#); Turns to the Right # degrees. May use RT(#);

Left(#); Turns to the Left # Degrees. May use LT(#);

Movexy(X,Y); MOVE a Distance X units and Distance Y units.

Draw(X,Y); DRAW a line going Distance X units and Distance Y units.

PenUp; No DRAWING will take place as the Turtle moves. (PU);

PenDown; Drawing is restarted. (PD);

NoUpdate; Nothing will update on the Canvas

Update; Resume showing the processing


LINE GRAPHICS:

Thickness (#); Width of line. {in pixels}

The total screen “Canvas” is only 1000 x 1000.

Blank (parm); Parm = Color (either a # or word)

Erase screen Canvas and set the background color

Color (parm); Parm = Color (either a # or word)

1) Blue 2) Green 3) Cyan 4) Red

5) Magenta 6) Yellow 7) White 8) Black

Multiples of Color: ie 9=1, 10=Green

TURTC:= color;

{TURTC is a Global Variable that can be used to set the color of the Turtle. Notice the Colon Equal (:=) is used to assign a value to a variable.}

Randcol(#); Generates a color between 1 and high number (#)

Multiples of Color: ie: 9=1=Blue, 10=2=Green, etc.

May be used to generate a RANDOM Number for example to be used with a SETXY position or initial direction of the Turtle.

LOCATION / POSITION:

Home; Return to center of screen and point cursor UP

The global variable TUTRD can be used to set the direction:

ZERO is UP.

SetX(n); Move to the X Point (Y does not change)

SetY(n); Move to the Y Point (X does not change)

SetXY(X, Y); Move to the Point: X, Y

Turtd(#); 0-Up (North)

270=Left (West) 90=Right (East)

180= Down (South)

TURTD:= #;


GRAPHIC SHAPES:

Circle(#); A circle with a radius of #

Blot(#); A filled in circle with a radius of #

Polygon(#); Connect the last # points and fill in object

You can set the color first with TURTC:=#

PolyLine(#); Connect the last # lines and fill in object

Forget(#); For use with POLYGON and POLYLINE to Forget the last points visited.

REMEMBER; Stores the last location (Point) of the Turtle.

GLOBAL VARIABLES:

TURTX / TURTY / TURTC / TURTD
X Position / Y Position / Color / Direction

Variable Assignment, Arithmetical and Boolean Operators and Constants

v := n make variable v equal to value n.

Arithmetic operators: + - * / MOD

Comparisons: = > < > <= >=

Boolean operators: NOT AND OR XOR

Boolean constants: TRUE FALSE (interpreted numerically as 1 and 0)

The CANVAS:

CANVAS(x1,y1,x2,y2) Where x1, y1 is the TOP LEFT Corner and x2, y2 is the BOTTOM RIGHT Corner.

The values are “Absolute Values” and not axtual X,Y coordinates. The “CENTER” home position adjusts to the Canvas Settings.

There are two options under the LAYOUT for

(0, 0, 1000, 1000) and (-1000, -1000, 1000, 1000)

PROCESS CONTROL:

FOR counter:= # TO # DO {Must define the VAR counter: Interger}

FOR counter:= # DOWNTO # DO {Count Backward}

For xyz:=1 to 360 do

Begin;

Forward (10); Right (20);

End;

REPEAT;

{Commands};

UNTIL condition;

IF condition THEN

Begin;

{Commands in here};

End;

IF condition THEN

{DO TRUE Command in here}

ELSE

{DO FALSE Command in here};

Reserved Words (Keywords)

These are “reserved words” or commands:

TURTLE GRAPHICS - TURTLE.exe

PJR Millican 2003 Version 7

AND

BEGIN

DO

DOWNTO

ELSE

END

FOR

IF

MOD

NOT

OR

PROCEDURE

PROGRAM

REPEAT

THEN

TO

UNTIL

VAR

XOR