Loops That Grow
A loop that does exactly the same thing every round draws the same shape over and over. Add one line that changes a variable, and suddenly each round is bigger than the last. That is how a spiral is born.
π‘ The idea
When a loop changes a variable each time round, the drawing spirals.
- Put set step 5 before the loop, so the box exists when the loop starts.
- Inside the loop, forward step uses the value and change step by 3 grows it.
- The turn stays the same. Only the length grows, so the path winds outwards.
- A turn of 90 gives a square spiral. A turn of 120 gives a triangular one.
- Grow by a small amount for a tight spiral, or a big amount for a loose one.
π Words to know
- spiral
- a path that winds outwards as it turns
- step
- how far the turtle moves this time round
- grow
- make a value larger each round
π Watch this
A square spiral winding outwards: every step is three longer than the one before.
set step 5 repeat 40 [ forward step right 90 change step by 3 ]
βοΈ Your turn
- Run it and follow the path from the middle outwards.
- Change change step by 3 to change step by 1. The spiral gets tighter.
- Change right 90 to right 91 and run it again. Look closely at the curve.
- Change repeat 40 to repeat 20, so the spiral stops earlier.
- Add colour rainbow at the top.
π― Challenge: Build a spiral out of triangles: turn 120 each time and grow the step by 5.
Show me one answer
set step 10 repeat 24 [ forward step right 120 change step by 5 ]
Your program