More Logo

Adapted with permission from a document by James R. King, copyight 1991.
 Mtht 480

In the introduction to Logo you learned several Logo commands and a little bit about programming. In this document, you will learn more about programming and do some math.

SetXY

Use the help feature to find out what the command setxy does. Use this command (four times) to draw a square.

Loops and Repeating Paths

Enter the following command.

repeat 52 [fd 50 rt 90]

You get a square, just as if you'd used the command repeat 4 [fd 50 rt 90]. It's not necessary to repeat 52 times, just 4. The extra 48 repeats just redraw the square twelve more times. Something similar happens when you enter the command repeat 17 [fd 50 lt 45 fd 50 rt 165]; try it. In both of the above examples we repeated a simple Logo command a lot of times, to get a closed figure. Will every Logo turtle path eventually close on itself if repeated often enough? Experiment with some simple commands to find out which do and which don't.

Total Turn

There is no visible difference in the results of repeat 52 [fd 50 rt 90] and repeat 4 [fd 50 rt 90], but there is an interesting mathematical difference between the commands. In the first command, the turtle is rotated through 90*52=4680 degrees, while in the second it rotates through 90*4=360 degrees.

The total turn of a turtle path is the sum of the signed angles of the turtle's turns. If we rewrite each left turn as a negative right turn (e.g. a left turn of 90 degrees equals a right turn of -90 degrees) the total turn is the sum of all the turns.

The total turn of repeat 52 [fd 50 rt 90] is 4680 degrees right.

The total turn of repeat 4 [fd 50 rt 90] is 360 degrees right.

The total turn of repeat 17 [fd 50 lt 45 fd 50 rt 165] is 17*(-45+165)=2040 degrees right.

The total turn of repeat 3 [fd 50 lt 45 fd 50 rt 165] is 3*(-45+165)=360 degrees right.

In the first two examples, the total turn of the command in brackets was 90 degrees right, and the figure drawn had four-fold rotational symmetry. In the third and fourth example, the command in brackets has a 120 degree right total turn and three-fold rotational symmetry. 90 = 360/4 and 120 = 360/3. Coincidence? Try repeating a command with 360/5 = 72 degree total turn and see what happens!

Try the following: repeat 15 [fd 60 rt 108]. What is the total turn? How many repeats are necessary to make the path close on itself? (I.e. what is the minimum number of repeats needed to make the figure resulting from that command?)

Record the total turn, the degree of rotational symmetry of the figure formed by repeating the command (if it exists), and the number of steps needed to close the path (if possible) for the following commands. You may also wish to record the number of lines of mirror symmetry of the final figure.

fd 50 lt 45 fd 50 rt 165
fd 50 lt 45 fd 50 lt 75
fd 50 lt 45 fd 80 rt 165
fd 50 lt 45 fd 40 rt 165
fd 50 lt 45 fd 50 rt 135
fd 100 lt 45 fd 50 rt 165
fd 50 lt 30 fd 50 rt 165
fd 50 lt 165 fd 50 rt 165

Question: What relationship do you find between the total turn and the rotational symmetry of the figure?

Question: If a path closes on itself, how many repeats are necessary to make it do so?

Challenge Question: What relationship did you find between the total turn and the number of lines of mirror symmetry of the figure?

Stars

Define the following procedure, try it out, and interpret its behavior in light of your findings in the previous section:

to star :num :denom
repeat :denom [fd 100 rt :num * 360 / :denom]
end

What is the total turn of [fd 100 rt :num * 360 / :denom], in terms of the variables num and denom? What is the total turn of repeat :denom [fd 100 rt :num * 360 / :denom]?

Choose a fixed value for denom (a prime number like 11 is a good choice). What is the effect of changing the value of num? For each different value of num, what is the total turn of [fd 100 rt :num * 360 / :denom]? How many times does the turtle's path wrap around the center of the star? (The turtle wraps once about the center of a square with the command repeat 4 [fd 100 rt 90] and twice with repeat 8 [fd 100 rt 90]. It wraps twice with repeat 5 [fd 100 rt 144] and once with repeat 5 [fd 100 rt 72].)


Mtht 480