Logo and Fractal

Logo is such a user friendly language that it is taught to fifth graders. In this course, we introduce you to a bit of Logo, but, admittedly, it is still only a tiny fraction of the full power of the language. If you would like to learn more about Logo, we have a tutorial.

In this excercise, we ask you to write several Logo programs, one to draw an animated object and a second to draw fractals and other geometric figures. Since a fractal program uses recursion, we ask you to explain the execution of one fractal generating program using the copy rule ("use of a procedure has the same effect as replacing it by a copy of its instruction").

Now that you are familiar with UNIX, we are going to ask you to play with Logo. In it type

 xterm -e /cs/bin/logo &
This will execute the actual program in a new shell. You will see that in that same shell it welcomes you to Logo and gives you a ? You can either test out the program by writing commands there (ie: fd 100) or load a file that you wrote in emacs by typing: (note, no end ")
 load "MyFile 
Once you have loaded your file, you can call whatever command that you set up in that file as though it were a Logo command.

Note: This assignment is the first assignment for the second semester introductory Computer Science course.


A. Write a Logo program to draw an animated sequence.

Your animated sequence should consist of at least one "moving" object in at least four frames. In order to design an animated sequence, simply draw a frame, clear the Logo window, and then draw the succeeding frame. Because the turtle moves so fast, this gives the illusion of motion. You might want to draw each frame multiple times to slow down the animation. You can animate almost any simple drawing; some examples are a driving car, a bouncing ball, or a running stick-figure. You could even have a floating letter or abstract design. Your object doesn't need to be highly detailed, but you should try to break it down into several drawing procedures. See the tree example in the Logo tutorial. Use a master procedure to animate the drawing:

   pu                               ; BEGIN FIRST FRAME
   setxy locAx locAy                ; move to first location
   pd
   drawobject                       ; draw object
   cs
   pu                               ; BEGIN SECOND FRAME
   setxy locBx locBy
etc.

Be creative and interesting- this is for your benefit!


B. Fractal Programs.

A fractal is a figure that has the self-similarity property. That is, if you look at a portion of the figure, it should have the structure of the entire figure.

In lecture you were shown a procedure to draw a fractal. It was based on the following triangle drawing procedure:

     to triangle :side
     repeat 3 [fd :side rt 120]
     end
This procedure causes the turtle to move forward along its current orientation by an amount given by the parameter side, turn right 120 degrees, and repeat these two operations two additional times.

A fractal procedure for part of the Koch snowflake is given below. Try executing it with side equal to 40 and 420.

     to snowflake :side
     if :side < 27 [fd :side stop]
     ; If the value of side is less than 27, then go forward and stop.
     snowflake :side/3
     ; Make the recursive call to snowflake with a new parameter
     ; of side divided by 3.
     lt 60
     ; turn left 60 degrees
     snowflake :side/3
     rt 120
     ; turn right 120 degrees
     lt 60
     snowflake :side/3
     end
To compile the entire snowflake you must substitute a call of the snowflake procedure into the triangle above in place of the forward movement. The Koch snowflake is also a fractal and like the trifractal in the lecture slides, it uses recursive calls. In order to follow the execution of this procedure clearly, use the copy rule for all four of the recursive calls and carefully keep track of the current value of side. Note that the turtle only draws a line segment each time the initial if statement is true and the value of side is less than 27.

a. Draw the entire snowflake with the value 2000 for side. Modify the program by changing the integer 27 in the if statement to 9 and execute it again. Try it again with a stopping value of 3.

b. Modify the triangle procedure to make a general polygon procedure. To do this you will have to add another parameter :number after :side so that you may input the number of sides. Then use this parameter to change the number of repeats and calculate the angle (currently 120). Using this new polygon procedure, draw a pentagon (5 sides) with a new length of 150.

c. Using the same modification made to triangle to produce snowflake, modify polygon to produce another fractal snowflake with more sides. Test this procedure by making a 5 sided snowflake.


HOME