Learning Goals 3 min
By the end of this lesson you will be able to:
- Use erase all, pen down, pen up, set pen size to (3), and set pen color to [] to draw a clean line drawing on a fresh Stage.
- Apply the polygon turn rule —
turn cw (360 / N) degreesinside repeat (N) — to draw an outer 8-sided shape, then mirror a smaller polygon at each vertex. - Combine two nested repeat loops into a symmetrical flower-style kolam, the kind families chalk on the doorstep for Deepavali.
Warm-Up — what makes a kolam a kolam 7 min
Every Deepavali, families across Malaysia draw a kolam on the floor in front of the door — chalk, rice flour, or coloured powder. The patterns are always symmetrical and built from repeated shapes. Today we'll teach Scratch to draw one.
Last lesson (SCR-L04-09) you used repeat (N) + turn cw (360 / N) degrees to draw single polygons. Try this in your head — if you write repeat (8) and turn cw (45) degrees, what shape will the cat draw?
Reveal the answer
A regular octagon. 360 ÷ 8 = 45, so the cat moves forward, turns 45°, moves forward, turns 45° — eight times. After the eighth turn it's pointing in the original direction, back at the start. Eight sides, eight equal angles, one closed shape.
Now the kolam twist. Imagine you draw the octagon — and at every vertex, before turning, you also draw a tiny second polygon (say, a small square) sticking outward. The result is an eight-petal flower with a square petal at each corner. That's the pattern we'll build today.
How many blocks will the inner shape add per vertex?
The inner shape will itself be a repeat + move + turn — that's one repeat C-block (with the inside counted once, because Scratch's stack cap counts blocks-on-screen, not blocks-executed). So we're still well inside L4's 30-block limit, even with two nested loops.
Today's project pulls together everything from Cluster B in one finished drawing — colour, pen-size, the polygon-turn rule, and nesting one polygon loop inside another.
New Concept — nested polygons and the kolam rule 15 min
A kolam is two ideas at the same time: a big shape made of small shapes. In code, that's a loop inside a loop.
The outer loop — the spine of the pattern
Pick how many petals you want. Eight is the classic kolam count. Whatever number you pick, that's your outer repeat, and the turn after each petal is 360 / N. For 8 petals, turn 45° each time.
repeat (8)
// draw one petal here
turn cw (45) degrees
end
The inner loop — one petal
A petal can be any closed polygon. To keep the maths friendly, use a square: repeat (4) + move (40) steps + turn cw (90) degrees. Drop the whole square into the outer loop where the comment was.
repeat (4)
move (40) steps
turn cw (90) degrees
end
Why the petal must close
This is the trick. Because the inner square ends with the cat at its starting point and facing the original direction, the outer 45° turn rotates the cat around the centre cleanly. The next petal grows out of the new angle. If the inner shape didn't close, every petal would walk away from the centre and you'd get a tangled mess instead of a flower.
repeat (8)
repeat (4)
move (40) steps
turn cw (90) degrees
end
turn cw (45) degrees
end
Setting up the canvas
Before the nested loops, the cat needs three setup blocks: erase all (wipe last run's drawing), set pen size to (3) (a chunky kolam line), and set pen color to [] with a festive colour — pick a warm orange or pink in the colour picker. Then pen down right before the outer loop.
Worked Example — an 8-petal kolam in ten steps 15 min
Open Scratch. We're going to build the full kolam from a fresh project — ten steps, one finished pattern. Make sure the Pen extension is added (bottom-left blue button → Pen) before you start.
Step 1 — Start fresh, centre the cat
New Scratch project. Default cat. Drag the cat to the middle of the Stage so it sits at x: 0, y: 0. Click point in direction (90) in the Motion palette to lock its starting direction.
Step 2 — Drop the hat
From Events: when ⚑ clicked.
Step 3 — Wipe and set up the pen
From Pen, snap in this order: erase all, set pen size to (3), set pen color to [] (click the colour swatch and pick a warm orange — like jubah orange).
Step 4 — Lift, jump to centre, drop
From Pen: pen up. From Motion: go to x: (0) y: (0) and point in direction (90). From Pen: pen down. (Doing these in code means the kolam looks the same no matter where the cat finished last time.)
Step 5 — Add the outer loop
From Control: repeat (8). Snap it under pen down. The C opens — that's where one petal will live.
Step 6 — Add the inner loop
From Control: repeat (4). Drop it inside the outer C. A second C opens inside the first.
Step 7 — Fill the inner loop
From Motion: move (40) steps, then turn cw (90) degrees. Both go inside the inner C. (That's one closed square petal.)
Step 8 — Add the outer turn
Back in the outer C, after the inner repeat's end, snap turn cw (45) degrees. This is what rotates each new petal 45° from the last.
Step 9 — Tidy: pen up at the end
After the outer repeat (8) closes, snap one final pen up so the cat doesn't leave a stray line if you drag it later.
Step 10 — Click the flag
The cat fires off — eight squares fanned around the centre, perfectly symmetrical, like a chalk flower at the front door. Click the flag again — wiped and redrawn instantly thanks to erase all.
The full assembled stack
when flag clicked
erase all
set pen size to (3)
set pen color to [#FF8A1F]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (8)
repeat (4)
move (40) steps
turn cw (90) degrees
end
turn cw (45) degrees
end
pen up
What you just built: a nested loop drawing. Two simple ideas (a square, and "do it eight times rotated") combine into something neither one could do alone. Every mandala-style pattern, every snowflake fractal, every spirograph in the world starts from this same nesting trick.
Try It Yourself — three kolam variations 15 min
Goal: Change the number of petals from 8 to 12. Don't forget to update both numbers — the repeat count and the outer turn cw () degrees. (Hint: 360 ÷ 12.)
when flag clicked
erase all
set pen size to (3)
set pen color to [#FF1F8A]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (12)
repeat (4)
move (35) steps
turn cw (90) degrees
end
turn cw (30) degrees
end
pen up
Think: Try 6 petals (60° outer turn). Try 16 petals (22.5° outer turn — Scratch accepts decimals). The kolam family is infinite.
Goal: Change the petal shape. Instead of a square inner loop, use a triangle: repeat (3) + turn cw (120) degrees. Keep the outer at 8 petals.
when flag clicked
erase all
set pen size to (3)
set pen color to [#1FB8FF]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (8)
repeat (3)
move (50) steps
turn cw (120) degrees
end
turn cw (45) degrees
end
pen up
Think: Each petal is now a tiny triangle pointing outward. Notice the kolam looks spikier than the square version — fewer sides per petal = sharper points. That's a real design decision Indian kolam artists make too.
Goal: Make the kolam rainbow. Inside the outer loop (but outside the inner one), add change pen color by (15) so each petal is a slightly different colour. Result: a colour-shifting flower.
when flag clicked
erase all
set pen size to (3)
set pen color to [#FF1F8A]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (8)
repeat (4)
move (40) steps
turn cw (90) degrees
end
change pen color by (15)
turn cw (45) degrees
end
pen up
Think: change pen color by () nudges the colour around the rainbow wheel. Eight petals × 15 colour-points = 120 worth of shift — about a third of the rainbow. Try 45 (one full wheel across the kolam) to see all the colours.
Mini-Challenge — Priya's lopsided kolam 5 min
"Why does my flower look like a comma?"
Priya wants a 6-petal kolam with triangle petals. She writes this:
when flag clicked
erase all
set pen size to (3)
set pen color to [#FF8A1F]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (6)
repeat (3)
move (50) steps
turn cw (90) degrees
end
turn cw (60) degrees
end
pen up
Look at every number. What did Priya get wrong?
Reveal one valid solution
The bug is the inner turn: turn cw (90) degrees. Priya wanted a triangle, and the rule is inner turn × inner repeat must equal 360. For a triangle: 3 × 120 = 360. But Priya wrote 3 × 90 = 270 — so the cat is 90° short of facing its original direction after each "petal". Every petal starts pointed a different way, and the whole thing drifts off in a spiral.
when flag clicked
erase all
set pen size to (3)
set pen color to [#FF8A1F]
pen up
go to x: (0) y: (0)
point in direction (90)
pen down
repeat (6)
repeat (3)
move (50) steps
turn cw (120) degrees
end
turn cw (60) degrees
end
pen up
One number changed — 90 to 120. The petal now closes, the cat returns to the centre direction, and the outer 60° turn fans the petals into a clean 6-pointed flower. The lesson: in nested polygon loops, the inner shape must close, or the outer pattern falls apart.
Recap 3 min
You built your first Cluster B pen project — a Deepavali kolam. The pattern is two polygons in one: an outer ring of N petals (turn 360 / N between each) and an inner closed shape that draws each petal. Because the inner shape ends where it began, the outer turn rotates each petal cleanly around the centre. Add erase all + pen down + a pen colour and you've got a tradition rewritten in code.
- Kolam
- A symmetrical floor design drawn at the doorstep for Deepavali and other South Indian festivals. Usually made of rice flour, chalk, or coloured powder.
- Nested loop
- A repeat inside another repeat. The inner loop runs all the way through for every single tick of the outer loop. Outer 8 × inner 4 = 32 trips through the inner blocks.
- Closed polygon
- A shape where the drawer ends at the same place and direction it started. The rule: repeat-N times, turn (360 / N) degrees. Squares close at 4 × 90°; triangles at 3 × 120°; hexagons at 6 × 60°.
- Outer turn
- The single turn block after the inner shape, inside the outer loop. It controls how far the next petal is rotated from the last. For N evenly-spaced petals,
360 / N. - Pen extension
- The dark-green Pen palette, added via the blue Add Extension button at the bottom-left of the editor. Adds pen down, erase all, set pen color to [], and friends.
Homework 2 min
The Festival Kolam Project. Design a kolam of your own choosing — for any festival or person you want to celebrate (Deepavali, Hari Raya, a birthday, Tahun Baru Cina).
- Start from the worked example. Save a copy as
HW-L4-10-Festival-Kolam.sb3. - Pick a petal count between 5 and 16. Update both the outer repeat (N) and the outer turn cw (360 / N) degrees.
- Pick an inner shape: triangle (3, 120°), square (4, 90°), pentagon (5, 72°), or hexagon (6, 60°).
- Pick a festive colour with set pen color to [], and a bold set pen size to () between 3 and 6.
- (Optional polish) Add change pen color by (15) inside the outer loop for a rainbow kolam.
- Set the Stage backdrop to a colour that suits your festival (Backdrops tab → fill).
Stay under L4's 30-block cap. The worked example is 15 — you have plenty of room.
Bring back next class:
- The
.sb3file. - A one-line answer to: "What outer turn did you use, and why is it exactly that number?"
Heads up for next class: SCR-L04-11 is the second Cluster B project — Spirograph. Same Pen extension, but instead of nesting one loop inside another, we'll use one very long loop with a tiny turn each time — and the curve emerges all on its own.