Star Student Builder logoStar Student Builder
← Code Makers Lesson 2Std 6-8

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 ]
What this program draws
What it draws

✍️ Your turn

  1. Run it and follow the path from the middle outwards.
  2. Change change step by 3 to change step by 1. The spiral gets tighter.
  3. Change right 90 to right 91 and run it again. Look closely at the curve.
  4. Change repeat 40 to repeat 20, so the spiral stops earlier.
  5. 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
Ask GuruAcharya Samayeshwar