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 "MyFileOnce 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.
pu ; BEGIN FIRST FRAME setxy locAx locAy ; move to first location pd drawobject ; draw object cs pu ; BEGIN SECOND FRAME setxy locBx locByetc.
Be creative and interesting- this is for your benefit!
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] endThis 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 endTo 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.