Goal: Change a slider´s setting as a spiral grows.
Vocabulary: repeat, set, carefully, announce
carefully [repeat 12 [fd howlong rt 90 sethowlong howlong + 5]]
[announce [The slider can't go any higher!]]
This project draws 12 lines of increasing length while the turtle turns right 90 degrees after drawing each line. The lines repeat and the turning angle stays the same, but the lengths vary.
- Make a slider and name it howlong. Set its minimum to 5 and its maximum to a large number such as 300.
- In the square-spiral procedure, repeat 12 means, "Repeat the instruction list 12 times."
Fd howlong means, "Move forward the number of turtle steps on the howlong slider."
Sethowlong howlong + 5 means, "Set the howlong slider 5 numbers higher than it is currently set."
- But we need to be careful, because we cannot set the slider higher than its maximum. This would produce an error message. We can place the sethowlong command inside of a carefully command to avoid an error message.
Carefully means, "Run the first input (a word or list of instructions). If there is an error, stop and run the second input (a word or list of instructions). If there are no errors, fine; ignore the second input." So in this case, if sethowlong exceeds the maximum on the howlong slider, the slider will stop at the maximum and we will see a message.
Announce displays the message in an alert box.
- Drag the slider back down to a small number before you start creating each new spiral.
Try clicking the button again after the turtle draws the spiral. Click it five times.
Can you make a tighter spiral (with lines closer together)?
On Your Own - Project Ideas
Can you revise the procedure so that with one button click the page becomes filled with one large twisting spiral?