TEACH VTURTLE                                     Aaron Sloman, Aug 1982

                          ---------------------
                          THE POP-11 VED TURTLE
                          ---------------------

This program simulates a turtle crawling around a rectangular picture,
leaving a trail of paint in the form of characters on a rectangular
grid.

The LIB command is needed to make the program available. You can do this
from inside VED as follows:

    press the ENTER key - the cursor will move to the command line
    type: lib vturtle
    press RETURN

This makes available a number of commands for drawing pictures,
including:

    DRAW(amount);
    JUMP(amount);
    LEFT(angle);
    RIGHT(angle)
    DRAWTO(column,line);
    JUMPTO(column,line);

You can get such commands obeyed by typing them in a file, marking them,
and using the CTRL-D sequence, as follows:

Mark the next line, using the 'MARK RANGE' keys, and then press CTRL-D
to get the line obeyed:

    jumpto(3,2); draw(5);

This tells the turtle to jump to column 2, line 2 of the picture file,
and then draw a line of asterisks. You will see a line of asterisks
appear in a file called 'picture'. If necessary use ESC X and ESC W to
look at it.

Now alter the numbers in the JUMPTO and DRAW instructions, and do it
again: Mark the line and press the CTRL-D key again to get the new
command obeyed. More asterisks will be added to the picture file. The
imaginary 'turtle' crawls along in a horizontal direction leaving a
trail of asterisks.

The picture is made up of a grid of square locations. Here is an
enlarged representation of part of a picture, showing some of the
asterisks.


            |------------------------
           4|   |   |   |   |   |   |
            |---+---+---+---+---+---|
           3|   |   |   |   |   |   |
            |---+---+---+---+---+---|
           2|   |   | * | * | * | * |
            |---+---+---+---+---+---|
           1|   |   |   |   |   |   |
            -------------------------
             1   2   3   4   5   6


Notice that we count rows from the bottom up, and rows and columns start
from 1. The lines surrounding the boxes are not drawn in the actual
turtle picture.

Initially, the turtle is ready to draw to your right, i.e. (heading is
"east"). The turtle starts off on the left of the picture, about 10
lines down. After moving 5 units to the right, its position is (6, 1).
(It doesn't mark the square in which it lands).

You can change the direction in which the lines are drawn as follows:

    left(45); draw(4);

Mark that line, with the MARK keys, then press CTRL-D. The LEFT command
changes the turtle's heading by 45 degrees, in a clockwise rotation. So
the second line goes at an angle to the first. It does not produce as
many asterisks as you may expect because the picture is essentially a
grid of squares, and if you draw a diagonal line across such a grid it
doesn't cover as many squares as a horizontal or vertical line of the
same length. (You can check that using graph paper and a ruler: though
if you know Pythagoras' theorem you'll understand why.) Try marking that
line and pressing CTRL-D again, several times.

You can clear the picture and start again with the command:

    turtle();

Try that. I.e. mark the line and press CTRL-D. Notice that the turtle
command helps you see the picture limits by drawing a line just below
the bottom of the picture.

The command JUMP can be used to make the turtle leave gaps in the
picture, e.g.

    repeat 20 times jump(5); draw(5); endrepeat;

Mark that line and press CTRL-D. Then try with different numbers.

The LEFT command can be used to make the turtle turn counter-clockwise.
Try the following, perhaps with different arguments for the DRAW
commands (mark the next 5 lines, then type CTRL-D):

    turtle(); draw(5);
    left(90); draw(5);
    right(90); draw(5);
    right(90); draw(5);
    left(90); draw(10)

Try again with angles of 45 or -45 degrees instead of 90. I.e. edit the
above commands, then use CTRL-D to get them obeyed. You will find that
if you draw diagonal lines (e.g. right (45)) they don't always go
straight. This has to do with the fact that the turtle doesn't always
end up in the middle of a square (Pythagoras again). You can cure this
by using the command TDRAW (for Tidy DRAW), and TJUMP (Tidy Jump).

You can make the turtle draw a zig-zag line as follows (mark the next
two lines then press CTRL-D)

    turtle();
    repeat 4 times draw(4); left(90); draw(2);right(90); endrepeat;

Use the command TURTLE to clear the picture, then edit the above command
to change the lengths of the lines drawn and the number of times it is
to be repeated.

In a sequence like:

        jumpto(1,5); draw(5);

The JUMPTO command puts the turtle on the left of the picture, five rows
up from the bottom of the picture. It was still facing to your right
(heading 0). The DRAW command told it to move a distance of five units,
leaving a trail. You can also use DRAWTO to make it draw to a specific
location. Try the following:

    jumpto(3,3); drawto(8,8);

Can you draw a square? Can you draw a capital H ?


-- MISHAPS -------------------------------------------------------------

If you mistype a command using CTRL-D, the result can be rather
confusing. The mishap message will appear in a file called 'output'. You
will then have at least three VED files: the TEACH file, the PICTURE
file and the OUTPUT file. The picture file will temporarily disappear.
However, you can edit the command to remove the error, then again mark
the range and press CTRL-D. To see what happens, mark the next line and
press CTRL-D:

    draw([five]);

After examining the error message in the other window, correct the line,
mark it and try again. This time you will get the picture file back. The
OUTPUT file, with the error message can be ignored, till your next
mishap. If for any reason the cursor gets left in the wrong file, you
can get back to this one by giving the ENTER TEACH command. I.e.

    PRESS the ENTER key
    TYPE teach
    PRESS the RETURN key

Syntactic errors are slightly different. You get a short error message
on the command line, without anything in the output file. To see this,
marking the following line, which has a missing semi-colon (don't
correct it), then press CTRL-D.

    jumpto(5,5) draw(6);

Here there is a 'separator' missing between ")" and "draw".


-- IF THE PICTURE BECOMES TOO BIG TO BE SEEN ---------------------------

Sometimes the picture will not fit into the visible window. E.g. try the
following:

    turtle(); jumpto(7,1);
    repeat 8 times draw(7); left(45) endrepeat;

You can then go and inspect the picture by moving to the other window
and then using the UP-SCREEN and DOWN-SCREEN keys, or other VED move
keys.

To move to the other window press the ESC key followed by X (eXchange
windows). Do the same to get back to this file afterwards. When looking
at the picture file you can enlarge the window by ESC W. When you come
back to this file,the normal window size will be re-set.


-- CHANGING THE PAINT --------------------------------------------------

Making a picture full of asterisks can be a bit boring. The variable
PAINT can be used to control the kind of 'trail' right by the turtle.
E.g. to make it use "+" instead of "*" do:

    "+" -> paint;

Try the following, or some variant:

    turtle();
    jumpto(3,3); "+" -> paint;
    repeat 4 times draw(4); left(90) endrepeat;
    jumpto(1,1); "." -> paint;
    repeat 4 times draw(8); left(90) endrepeat;

If you are using Xved on a colour display, you can use coloured paint.
For example, if the following lines of code will produce a
multi-coloured square:

    turtle();
    '\{2}#' -> paint;       ;;; red
    draw(4); turn(90);
    '\{4}#' -> paint;       ;;; green
    draw(4); turn(90);
    '\{6}#' -> paint;       ;;; blue
    draw(4); turn(90);
    '\{0}#' -> paint;       ;;; normal black
    draw(3);

As you can see, the syntax for notating colours is a little complicated,
however if you copy it exactly you shouldn't have problems.


-- STOPPING ------------------------------------------------------------

If you've had enough for now, PRESS ESC then the Q key to abandon this
TEACH file.

You can come back later and continue from this place if you note the
line number in the status line, above. To jump to line 110, say, you can
do
    TEACH VTURTLE
then
    press ENTER, then type 110 then press RETURN.

(Try that now, for practice.)

If you leave POP11 now and come back later, you'll have to give the

    lib vturtle;

command again, to get the turtle ready.


--- to be continued ---

HELP * TURTLESUM gives a summary of turtle procedures.


--- C.all/teach/vturtle
--- Copyright University of Sussex 1994. All rights reserved.
