Home
Project Folders
Teacher Resources
Student Resources
En ESPAÑOL
How Do I?
Vocabulary
MWForum
Site Map
Search
Our Team

spirals 1 2 3 4 5 6 7 8 9
Spirals 5
Download
11 KB


Goal:   Use recursion to limit a spiral´s size.


Screenshot


Vocabulary:   if, > (greater than sign), stop

Code
Project Map

to spiral :length
if :length > howbig [stop]
pd
setc whatcolor
setpensize howthick
fd :length rt angle
spiral :length + howtight
end

to reset
cg
end



Notes

When we call the spiral procedure from within the spiral procedure, that tells the computer to start running the procedure all over again.   (A procedure which calls its own name is called a recursive procedure.)   The computer will keep circling back to the beginning forever unless we tell it when to stop.

  1. Instead of setting the number of turns as in Spirals 4, we make a howbig slider to set a limit on the length of the lines.

  2. In the spiral procedure, if :length > howbig [stop] means, "If the value of the length variable is greater than the number on the howbig slider, stop the procedure."  

    Every time the computer runs the spiral procedure, it checks to see if the if command is true.   If it is true, the procedure will stop.   If it is false, the procedure will keep running.

  3. Spiral :length + howtight means, "Start running the spiral procedure again, but increase the value of length by the number on the howtight slider."

    When the recursive call takes place at the end of a procedure, it is called tail-end recursion.

  4. You should always save your work before you test out a recursive procedure, in case it doesn't stop as you expect.   Also, you can always interrupt a process by selecting "stop all" from the pull-down Edit menu.




What If?
Try different settings on the angle, howtight, and howbig sliders.


Challenge
Can you set the sliders so that the turtle will draw a spiral that reaches the top and bottom of the project page without wrapping?


On Your Own - Project Ideas
Can you revise the procedure so that the spiral starts out drawing large lines that gradually shrink?





© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.