Topic 12 - Stars, Squirals and SpiralsTry this :
TO STAR :LENGTH
FD :LENGTH RT 20 BK :LENGTH * 2
STAR :LENGTH
END

Or this:
TO SUN :LENGTH
FD :LENGTH BK :LENGTH * 2 FD :LENGTH RT 20
SUN :LENGTH
END
Try increasing the value of len with each call to sun.
Now try this :
TO SQUIRAL :LENGTH
REPEAT 2 [FD :LENGTH LT 90]
SQUIRAL :LENGTH + 3
END
Enter 'squiral 3' at the command line. The pattern has elements of both a square and a spiral, hence the name 'squiral'.

You can edit this procedure to produce some very interesting effects.
First of all try changing the '2' to '3' and the angle from '90' to '60' in line 2 - this draws a hexagonal spiral. Notice that the sum of angles on this line is 180 because the turtle draws only half the shape before the length is increased. Thus an 8 sided pattern will have numbers '4' and '45' on line 2 as 4*45=180.

The second change you can make is to set the angle of turn to a value just above or just below that required to draw the pattern, for example:
REPEAT 2 [FD :LENGTH LT 89.5]
or:
REPEAT 3[FD :LENGTH LT 60.5]
You will see a spiral shape with 'curves' drawn from straight lines.

To produce a better spiral you need to change the angle as well :
TO SPIRAL :LENGTH :ANGLE
FD :LENGTH LT :ANGLE
SPIRAL :LENGTH + 0.05 :ANGLE - 0.05
END
Enter 'spiral 1 20' at the command line. Note that the angle starts off at 20 and is then reduced by a small amount each time. Experiment with starting values for both len and ang, and try changing the minus to plus.

Finally try this one:
TO SPIRAL :SIDES :LENGTH
IF :LENGTH > 200 [STOP]
FD :LENGTH RT 360 / :SIDES
SPIRAL :SIDES :LENGTH + 3
END
This brings together many of the things you have learned in the last few sections. What is the minimum value of :SIDES that you can enter?
You can distort the spiral as before by changing the third line of the function to something like this:
FD :LENGTH RT 360 / :SIDES * 1.01
You now have a mathematical laboratory in which you can change the geometry of the shapes you produce by changing the variables or parameters of a function.