.........1.........2.........3.........4.........5.........6.........7.........8


TURTLE GRAPHICS
by Ian Collier
from Your Computer, September 1985

Ian Collier with a Logo graphics program for the Spectrum.


This is an implementation of the turtle graphics part of Logo, adapted
into about 15 commands.

To set up the machine code the listing of data must be entered and run.
The data will be read and POKEd in by the BASIC program.

After creating the graphics code it should be ready for use at 30000.
It may, however, need to be moved, for example a higher address in a
48k Spectrum. Having saved the code with:
	SAVE "logo" CODE 30000,1600
the relocate program will move the code, first by loading it in at the
new address, if this has not already been done, then changing the
absolute addresses. A copy of the code at 30000 should be retained for
the demonstration program.

Program 1 allows you to use the turtle graphics without writing a 
program. It incorporates one loop using the control variable 'a', which
can be set up. Commands are as follows:

DIR x     - Points turtle in a direction x degrees anti-clockwise 
            from horizontal right.
CIR x     - Draws a circle around the turtle, radius x pixels.
BOX x,y   - Draws a box with two diagonally opposite corners at the
            turtle and (x,y).
FOR x     - Moves the turtle forward x pixels, leaving a trail.
BOR x     - = BORDER x
FIL x,y,z - Fills in any enclosed area in INK z, starting at (x,y). If
            filling starts at the edge of the area, then it is possible
            that only half will be filled, so aim for the middle.
POL x,y,z - Draws a polygon with x sides, moving first to (x,y) and
            going anti-clockwise.
INK x     - Any further drawing will be in INK x; this only lasts to
            the end of the line of instructions.
JUM x     - Moves the turtle forward x pixels without changing the
            screen (jump).
ROT x     - Rotates the turtle x degrees anti-clockwise.
MOV x,y   - Moves the turtle to (x,y).
PLO x,y   - Moves the turtle to (x,y) and plots a pixel.
SCR x,y   - Changes the screen colours to PAPER x and INK y without
            erasing the patterns.
REP x     - Marks the start of a set of instructions to be repeated x
            times. Also sets up the BASIC variable Rep which is equal
            to the counter of the innermost loop. Note Rep starts at x
            and goes down to 1.
END       - Marks the end of the repeated instructions.

The instructions can be in upper or lower case.

The prompt "Instructions" will appear and the instructions must be
typed in (I have printed out some examples. Then the prompt "FOR a="
will appear and you must set up the loop as in BASIC by typing three
numbers followed by ENTER; eg.
	FOR a= 1 TO 50 STEP 1
If a loop is not required, three 1s can be entered.

If a mistake has been entered in the instructions, the program will 
stop with a report. Otherwise, the instructions will be carried out
and you may then enter some more. Each time a set of instructions is
entered, the screen is cleared and the turtle is moved to the centre 
of the screen and pointed horizontally right.

To use the commands in a program they must be initialised. If the code
is still in its original position, this is done by:
	RANDOMIZE USR 30000
The syntax checker will now accept the new commands, but to use the
commands they must be re-initialised if the program has been altered.
This is so that the new position of the variables is recognised, and
the new defined procedures are found. The commands need to be initialised
after CLEAR and RUN, as these reset the machine stack. If Interface 1
is connected, this adds complications.

The new commands are regarded by the program as syntax errors unless
followed by a turtle graphics command, but they work within a program.
Also, where one of the new error reports - eg. Microdrive not present -
is caused, this resets the machine stack and the graphics commands need
to be re-initialised.

To enter the new commands, they must be placed inside quotes, but at
the end of a line the final quotes may be omitted. For use in a program
there is one more command - CAL.

It calls instructions at the address given. If these instructions are
in a string, the address of the instructions needs to be found and the
string needs to be prepared by inserting the hidden floating point forms
after the numbers - these will not be hidden in a string and will appear
as question marks and other characters. This is done by the routine at
31500 and is demonstrated in Program 1 in lines 145 & 9510.

New commands are like definable procedures. For an example see the
command .STA in the demo program. To define a procedure, open quotes as
usual and type a full stop followed by the three-letter name, then a
colon. The commands following this will be executed every time the new
command is encountered. The end of the defined command is at the first
close quotes encountered in the definition, or at the end of the line.
