FROM THE METRO-ORLANDO AUG (MOAUG)
NEWSLETTER.
A SERIES of articles on LOGO by RICKI
GERLACH.
 
We hope to distribute future parts of
this series.

             PART 3
^N ^A ^D
Once we understand how to move the
turtles around, we can do some simple
but nice displays.  The easiest one
would be to draw a tree.  In order to
do this, we first decide that we want
to draw a branch.  To do this, we
write the procedure:

     TO BRANCH: SIZE
     RT 90
     FD: SIZE / 2
     WAIT 30
     TR2: SIZE / 2
     BK: SIZE
     BRANCH: SIZE
     END

What we have done here is to define
the procedure BRANCH.  When you run
the procedure, you have to input a
number SIZE so that BRANCH will know
how far to draw the branch.

Now we add another procedure, TR2, to
add to the tree by extending the trunk
and adding another branch.  It places
the added branch on top of the tree,
at half the size of the first one. Add
another procedure, TR2:

   TO TR2 :SIZE
   IF SIZE < 10 [STOP]
   FD :SIZE
   WAIT 30
   TR2 :SIZE / 2
   BK: SIZE
   BRANCH :SIZE
   END

If we look at this procedure, we will
notice several things.  First, we are
telling ADAM that if our number, SIZE,
is smaller than 10, then stop the pro-
cedure.  Second, the WAIT command
tells ADAM to stop for the count of 30
before continuing the program.  Last,
we see that we are dividing the number
we inputted by 2 (shown in the line:
<TR2 :SIZE / 2>.)  We also see that
the procedure BRANCH, which we defined
earlier, is being called from within
this new procedure.

We will write one last procedure,
which we will call TREE.  It will look
like this:

   TO TREE :SIZE
   IF OR :SIZE < 10 :SIZE >110 [STOP]
   ST CS
   PU SETPOS [ 0 -80] PD
   TR2 :SIZE
   HT WAIT 180 CT
   END

Now, you have to save this program
under the name TREE.  In order to do
this, enter:

   SAVE "TREE

Note that you will use quotation marks
only at the beginning of the file
name, not at the end.  Make sure that
you have a disk or datapack in your
drive before saving the file. After
it's saved, you can run the program by
entering the name and any number.  For
example, try this:

   TREE 50

...and see what  happens.  Notice you
do not have to use the command RUN, as
you would in BASIC.  This program
draws a very crude tree, but shows
very clearly how complex recursion
works.  By calling back on itself, the
program could go on and on forever. To
prevent this, we added a test
condition to stop the recursive calls
going on indefinitely.  The test
condition is the " IF OR " found in
the TREE procedure, line two. We've
added a half second pause to let you
see the turtle draw each of the trunks
first, then draw each branch.  One
important factor, in recursive calls,
is that the turtle MUST return to its
previous position; hence the turtle
goes back to the bottom of the trunk,
facing up.

This is shown in line four, where we
put the pen in the up position (PU)
and set the position of the turtle,
then put the pen back down (PD).

      (continued next month)


