Spirals
This session aims to teach you how to construct various kinds of spiral using Logo.
If you have not had a go at the other exercises before this one then it might be worth giving them a go.
You are going to edit a routine called "spiral. Once you have programmed this routine into Logo you can then call it just like one of the normal Logo commands.
Get Logo running in the normal fashion and then call up the routine editor by entering "spiral.
edit "spiral | |
Now edit the code so that it reads like this. to spiral :size | |
Now click on the "file" menu and select "save and exit". | |
Now enter the command spiral 120 :size is known as an argument of the routine spiral. By typing "spiral 120" you have started the spiral routine off with a value of 120. The turtle will spiral inwards starting with a line 120 pixels long. | |
If you look carefully you will notice that the turtle is still trundling around inside the spiral. This is because your program doesn't know when to stop. The line just gets shorter and shorter. You can stop it by using the HALT button. It is a bad thing to write programs that don't stop as they will eventually lock up your computer | |
You can fix this by adding another line of code to your routine.
to spiral :size This code uses the if function to check that :size hasn't got too small. If :size is still big enough then spiral calls itself to draw another section of the spiral. When a program calls itself this is known as recursion. |
Task 1 Simple Spirals
Use your routine to make different shapes of spiral. Cut and paste a few into paint to make a poster.
At the moment you can only spiral inwards. It would be good to be able to spiral outwards, to control the angle of the spiral and how quickly the length changes.
Edit your code again by getting the editor window up. edit "spiral Now alter the code to look like this. Remember to "save and exit" once you have put it in.
to spiral :size :angle | |
To draw a spiral with your new program type: spiral 100 45 | |
This code allows you to change all three variables, size, angle and ratio.
to spiral :size :angle :ratio | |
So, you now need to type in 3 arguments after spiral: spiral 120 60 0.995 | |
You might have noticed that there is a little extra code in the latest version of spiral. This code allows you to use values of :ratio that are bigger than 1. The routine stops when :size reaches 200. "save and exit" from the editor before typing: spiral 20 45 1.005 |
Task 2 Inward and Outward Spirals
Have a go at making lots more spirals. Save the nicest in paint.
You can also use shapes to spiral with. Try these ideas out.
to spiral :size :angle :ratio The pu and pd commands lift and lower the pen to stop the turtle drawing. | |
Use these arguments: spiral 120 72 0.9 | |
Try this one out.
to spiral :size :angle :ratio Use these arguments: spiral 120 30 0.95 |