Gregory, Senior Lecturer in Mathematics at Bradford and Ilkley Community
College, continues his series of Geometry Microworld Part III.
In GO 11 we saw that the procedure POLY :NUM :SIDE can be used to draw not only any regular polygon we wish but also very good approximations to circles, and arcs of circles.
This procedure embodies the idea that a circle can be thought of as a regular polygon with a 'very large' number of sides - as the number of sides increases, the figure drawn becomes closer and closer to what we normally think of as a 'perfect' circular curve.
Can this idea be used to make the Turtle produce other kinds of curves?
Before we can take this notion very far, it will be useful to develop a further programming idea which will greatly increase the scope of what we can get the Turtle to do.
First of all, make the Turtle draw a circle, although this will be very slow. In order to walk along a circular path, we must take a step forward, turn a little, take another step forward, turn a little ------ and just keep on doing this - a rather tedious business!
A very simple procedure should do this:
But this is going to be ridiculous - far too many stops will be needed to make a sensible procedure.
Try this instead:
The new idea here, that of recursion, is that the procedure calls itself, or rather calls another copy of itself. Probably the only way to get used to the idea is to act it out and see how it forces the same steps to be taken again and again.
When does the procedure end? Well, of course, it doesn't - we will have to press ESCAPE to stop it running when we decide we have had enough.
POLY again: We can now re-write the procedure POLY this time using the idea of recursion.
Again, the procedure will not come to an end. How to put stop instructions into recursive procedures will be dealt with in a later issue.
We can now go a step further. So far, we have varied the size of each step (SIDE). We can also vary the size of the turn:
Note that when the procedure calls a copy of itself, the copy must have the same number of variables as the original.
Drawing a Spiral:
Instead of using '10' as the increment each time, investigate how varying this number affects the appearance of the spirals.
|© 2004. Amethyst Consultancy Ltd.|