 x	O                                                                  PART 4 

                   BY: RICKI J. GERLACH 
 
Now that we understand a little about moving the turtles around, in Logo, we can do some rather unique and pretLEARNING WITH LOGO IS A REGULAR COLUMN OF RICKI GERLACH WHICH APPEARS IN THE MOAUG newsletter. 
[See MOAUG newsletter for earlier lessons]

                    LEARNING WITH LOGO
                    
                          PART 4 

                   BY: RICKI J. GERLACH 
 
Now that we understand a little about moving the turtles around, in Logo, we can do some rather unique and pretty designs with Logo. We can write our own procedures, using the complex recursions to draw for us. This program will draw triangles inside of larger triangles (nested so to speak). We can better visualize how this process works if we first remove the recursive call. We enter the following procedure: 
 
TO NEST.TRI :SIZE 
IF OR :SIZE < 10 :SIZE > 180 [STOP] 
ST CS 
PU SETPOS [ -30 -30] PD 
NTRI :SIZE 
HT WAIT 180 CT 
END 
 
Now we enter the procedure 
 
TO NTRI :SIZE 
NTRI :SIZE / 2 FD :SIZE RT 120 
END 
 
Now we enter the command: 
 
NEST.TRI 60 
 
First, we notice that if we remove the recursive call, NTRI draws a simple triangle, so long as the input :SIZE is larger or equal to ten. However, with the recursive NTRI buried in the REPEAT command, we see that it is called again (repeats 3 times) with new inputs, :SIZE/2, before the turtle takes even one step forward. Thus, the smaller, inside triangles actually are called at successively lower levels (and smaller sizes) until a STOP is reached. Then, as the procedures retrace their steps (at increasingly higher levels), the triangle part of each procedure is completed. The last triangle to be drawn is the   largestone, done at toplevel. To see this, enter the next procedure: 
 
TO NTRI :SIZE 
IF :SIZE < 10 [STOP] 
REPEAT 3 [NTRI :SIZE / 2 FD :SIZE RT 120 ] 
END 
 
To run, enter a command, such as 
 
NEST.TRI 60 
 
and watch what happens now to the single triangle.
     
Now, lets enter a program to draw other polygons.  Before we do, we either have to save the above, by entering 
 
SAVE "NEST.TRI 
 
or just erase the procedures, in which we would enter 
 
ERALL RECYCLE 
 
If you decide to first save it to disk, make sure to erase the procedures after saving them. The next set of procedures will draw squares, pentagons, hexagons, circles, etc. The number of sides to the polygon is given by the variable N. It is possible (and often desirable) to draw smaller polygons inside of the larger ones. Nested recursion makes this possible. The variable DEPTH controls the number of levels of recursion that takes place. If the value of DEPTH is one (1) the recursive process goes on indefinitely, with no drawings made. If the value of DEPTH is large, about 10, then only one polygon is drawn. 
The procedures are as follows: 
 
TO NEST.POLY :SIZE :N :DEPTH 
IF :SIZE < 10 [PR [SIZE TOO SMALL !] STOP ] 
IF :N < 4 [PR [NEED AT LEAST FOUR SIDES !] STOP] 
IF :DEPTH < 2 [PR [DEPTH TOO SMALL !] STOP ] 
ST CS 
PU SETPOS [ 0 0 ] PD 
NPOLY :SIZE :N :DEPTH 
HT WAIT 180 CT 
END 
 
TO NPOLY :SIZE :N :DEPTH 
IF :SIZE < 10 [STOP] 
REPEAT :N [POLY :SIZE / :DEPTH :N :DEPTH FD :SIZE RT 360 / :N ] 
END 
 
Save this under the name NEST.POLY 
Now, you can try some of the following for different designs: 
 
NEST.POLY 100 4 2 
NEST.POLY 30 13 2 
NEST.POLY 60 7 2 
NEST.POLY 40 6 4 
 
Experiment with the inputs, to get different designs.
n by the variable N. I
