Use the secret variable repcount
to jazz up patterns to the max.
When you use the rpt _n_ [...]
command to repeat something n times, you can use the secret variable repcount
or #
inside the square brackets. It is set to current turn around the loop.
Try it out with:
rpt 10 [ say # ]
This means you can alter the path made by the turtle every time you do another loop. You remember the code for a square? rpt 4 [ fd 5 rt 90 ]
will draw a square with sides of 5 units. Try changing the length of each side every time around the loop. There is no need to stop after only 4 repeats. Try this:
setpc blue setps 10
rpt 14 [ fd # rt 90 ]
You can do maths on the number returned by repcount
. For example, divide it using the /
operator. Try this:
rpt 28 [ fd #/2 rt 90 ]
What happens if you divide by more than 2, or less?
Try changing the angle for rt
to something a little more or a little less than 90. Experiment with different angles.
rpt 200 [ fd #/10 rt 88 ]