.sb3 and share the link — you built a real function.Learning Goals 3 min
By the end of this lesson you will be able to:
- Add the Pen extension and use pen down / pen up / erase all to make a sprite draw shapes on the Stage.
- Define a My Block with one number input — draw star (size) — and tick Run without screen refresh so the whole shape appears in one frame.
- Combine your new My Block with pick random (30) to (80) and go to x: () y: () to scatter five different-sized stars across the Stage at the press of the flag.
Warm-Up — five different-sized stars by hand 7 min
Last lesson (SCR-L03-18) we took a long, repeated script and refactored the repeated part into a My Block. Today's warm-up is the question that proves we need My Blocks at all.
Imagine your teacher tells you: "Draw five stars on the Stage. One small, one medium, one large, one bigger, one biggest. They should be in five different random spots." Without My Blocks, how many move-and-turn blocks would you need?
Reveal the answer
A 5-pointed star is 5 points × 2 blocks per point (move + turn) = 10 blocks per star. Five stars = 50 blocks, plus another 5 go to x: () y: () blocks to scatter them, plus pen-up / pen-down pairs. You'd run into Level 3's 20-block stack cap before you finished the second star.
One more — Aniq draws his first star and the cat looks like it's walking the star: side, pause, turn, side, pause, turn. Each line appears one at a time. He wants the whole star to appear instantly. What's the setting he's missing?
Reveal the answer
Inside the My Block define screen there's a tick-box called Run without screen refresh. Tick it, and Scratch runs the whole block in one frame — no animation, just the finished drawing. It's the difference between "watch the cat slowly trace a star" and "blink and a star appears." Today's project depends on it.
Today we'll build draw star (size) once, tick run-without-refresh, and then call it five times with five random sizes — the entire Cluster-C journey in one project.
New Concept — Pen, inputs, and run-without-refresh 15 min
This lesson stitches together three ideas you've met separately. Let's pull them all the way through.
Idea 1 — the Pen extension
Out of the box, Scratch sprites can move but they don't leave a trail. The Pen extension adds that trail. To turn it on, click the little blue Add Extension button in the bottom-left of the Scratch editor, then pick Pen. A new dark-green palette appears.
erase all
pen down
move (50) steps
pen up
Pen blocks live in the My Blocks palette area at the bottom of the block menu, but they have their own dark-green colour. Don't confuse "pen" with "My Blocks" — they're separate palettes that happen to sit next to each other.
Idea 2 — a My Block with a number input
You met inputless My Blocks in SCR-L03-17 and refactoring in SCR-L03-18. Today the My Block takes one number — the size of the star.
To make it: My Blocks palette → Make a Block. Type the name draw star. Click Add an input · number or text. A round slot appears with a default name (rename it to size). Tick the box that says "Run without screen refresh". Click OK.
define draw star (size)
repeat (5)
move (size) steps
turn cw (144) degrees
end
Notice the (size) oval inside the move block. That's the parameter — it gets replaced by whatever number you pass in when you call the block. Call draw star (30) and every move (size) steps becomes move 30 steps. Call draw star (80) and every move becomes 80. One definition, infinite star sizes.
Idea 3 — Run without screen refresh
Normally, Scratch redraws the Stage about 30 times per second. So if your My Block has ten blocks inside, the user sees ten tiny frames of progress. For a star, that means watching the cat slowly trace each line — about a third of a second of animation.
When you tick Run without screen refresh on the define block, Scratch promises: "Don't redraw the Stage until the whole My Block finishes." All ten blocks fire in one frame. The star appears instantly, as if drawn by a stamp.
Worked Example — five random stars across the Stage 15 min
Open Scratch. We're building the full project in ten steps. You'll end up with a one-click flag that scatters five different-sized stars in random positions every time.
draw star (size) My Block. The cat (✏️) is hidden so only the stars show.Step 1 — Add the Pen extension
Bottom-left of the editor: blue Add Extension button. Pick Pen. The dark-green Pen palette appears in your block menu. You'll need it from Step 5 onwards.
Step 2 — Make the My Block
My Blocks palette → Make a Block. Name: draw star. Click Add an input · number or text and rename it size. Tick "Run without screen refresh". Click OK. A pink define draw star (size) hat appears in the script area.
Step 3 — Fill the definition
Under the define hat snap: repeat (5). Inside the repeat: move () steps — drag the pink (size) oval from the define hat into the round slot. Then turn ↻ (144) degrees. That's the whole My Block.
define draw star (size)
repeat (5)
move (size) steps
turn cw (144) degrees
end
Step 4 — Test it once by hand
Drag a fresh draw star (size) call onto the script area (it lives in My Blocks now). Type 50 into its slot. Click the call. Nothing visible happens — because pen isn't down yet. That's fine; the star drew, it just wasn't inked.
Step 5 — Build the main flag stack
From Events: when ⚑ clicked. From Pen: erase all. Snap them.
Step 6 — Make a repeat-5 for the five stars
From Control: repeat (5). Snap it under erase all.
Step 7 — Inside the loop: lift pen, jump to random spot
From Pen: pen up (so the jump doesn't draw a streak). From Motion: go to x: () y: (). Into the x slot drop pick random (-200) to (200). Into the y slot drop pick random (-150) to (150). (Stage is 480×360, so those ranges keep the star centre on-screen.)
Step 8 — Pen down, then call draw star with a random size
From Pen: pen down. Then from My Blocks: draw star (). Into its slot drop pick random (30) to (80). The repeat loop now lifts the pen, jumps, drops the pen, draws a random-size star — five times.
Step 9 — Tidy: pen up after the loop
After the repeat (5) closes, snap one more pen up so the cat doesn't drag a line as you move it around afterwards.
Step 10 — Click the flag and admire
Five different-sized stars appear instantly, scattered across the Stage. Click the flag again. Five new stars, new sizes, new positions. The old ones are wiped because we put erase all right at the top.
The full assembled stack
define draw star (size)
repeat (5)
move (size) steps
turn cw (144) degrees
end
when flag clicked
erase all
repeat (5)
pen up
go to x: (pick random (-200) to (200)) y: (pick random (-150) to (150))
pen down
draw star (pick random (30) to (80))
end
pen up
What you just built: a small function in the computer-science sense. draw star (size) is a tool you invented. It hides ten blocks of work behind one tidy call. Every game you build from now on — particle effects, level generators, custom enemies — leans on this same idea: package a useful chunk of work, give it a name, give it inputs, call it.
Try It Yourself — three drills 12 min
Goal: Add a colour change. Before each draw star () call, use set pen color to () with a random colour. (Hint: set pen color to (pick random (1) to (200)) works because pen colour is a number.) Each star a different rainbow shade.
when flag clicked
erase all
repeat (5)
pen up
go to x: (pick random (-200) to (200)) y: (pick random (-150) to (150))
set pen color to (pick random (1) to (200))
pen down
draw star (pick random (30) to (80))
end
pen up
Think: The My Block didn't change at all. You only edited the caller. That's the power of a well-named function — you can decorate around it without touching its insides.
Goal: Make a second My Block called draw triangle (size). Same idea, but repeat (3) and turn ↻ (120) degrees. Then in your flag stack, scatter 3 stars and 3 triangles in random spots.
define draw triangle (size)
repeat (3)
move (size) steps
turn cw (120) degrees
end
Think: You're seeing the secret of regular polygons: repeat-N times, turn (360 ÷ N) degrees. Star is the odd one out because it uses 144 (the double-angle that makes points cross). Square would be repeat-4, turn-90. Hexagon would be repeat-6, turn-60.
Goal: Make draw star (size) take a second input — points. The body uses repeat (points) and turns by ((360) * (2)) / (points). Call draw star (60) (5) for a normal 5-point star, or draw star (60) (7) for a 7-point spiky star.
define draw star (size) (points)
repeat (points)
move (size) steps
turn cw (((360) * (2)) / (points)) degrees
end
Think: You just generalised the function — one My Block now draws every odd-pointed star from 3 upwards. This is the next big leap: writing a tool that's more powerful than the problem you needed it for.
Mini-Challenge — Mei's slow-drawing stars 5 min
"Why does each star take so long?"
Mei built the project and her stars do appear at random sizes in random places — but each one draws slowly, one line at a time, like the cat is jogging around an invisible track. By the time the fifth star finishes, ten seconds have passed. She wants all five stars to appear instantly. Here's her define:
define draw star (size)
repeat (5)
move (size) steps
turn cw (144) degrees
end
What's the one-click fix?
Reveal one valid solution
Mei forgot to tick Run without screen refresh when she made the block. With the box unticked, Scratch redraws the Stage between every block inside the My Block — so we see each line being traced.
To fix it without rebuilding: right-click the define draw star (size) hat → Edit. The same dialog that made the block reopens. Tick Run without screen refresh at the bottom. Click OK.
Click the flag. All five stars now appear in the same frame — instantly. Lesson: if a My Block does anything visual (drawing, stamping, building a shape) you almost always want run-without-refresh on. Save the slow animation for things that should be slow — like a sprite walking.
Recap 3 min
You finished Cluster C by building a real function: draw star (size). You added the Pen extension, made a My Block with one number input, ticked Run-without-screen-refresh so the shape appears in one frame, and called it five times with random sizes and positions — a 60-block project squashed into 13 blocks. From now on, every time you find yourself copy-pasting a chunk of script, you'll hear the question: "Should this be a My Block?"
- Function
- A reusable named chunk of work with inputs. In Scratch, a function is a My Block with parameters. draw star (size) is a function whose input is
size. - Parameter
- The named input on a My Block's define hat. Inside the body, the parameter shows up as a pink oval you can drag into any number slot.
- Pen extension
- An add-on palette (dark green) that lets a sprite draw lines on the Stage. Enabled via the blue Add Extension button at the bottom-left of the editor.
- Run without screen refresh
- A tick-box on the My Block define dialog. When ticked, Scratch finishes the whole My Block in one frame instead of redrawing between blocks. Makes drawings appear instantly.
- Polygon angle rule
- To draw a regular N-sided shape, repeat N times and turn
360 / Ndegrees. For a 5-point star, use144(which is360 × 2 / 5) so the lines cross to make points.
Homework 2 min
The Star-Field Project. Make a one-flag-click "night sky" using your new My Block.
- Start from your worked-example project. Set the backdrop to a dark colour (Backdrops tab → fill with dark blue or black).
- Change the repeat in the flag stack from repeat (5) to repeat (20). (20 stars — well under the polygon-cap; one My Block call doesn't add stack depth.)
- Before pen down, add set pen color to (pick random (1) to (200)) so each star is a different colour.
- Make the size range smaller: pick random (15) to (40) — tight little stars look more like a sky.
- Add a hide at the top so the cat isn't standing on the night sky.
Save as HW-L3-19-Star-Field.sb3. Hit the flag — twenty differently-sized, differently-coloured stars should scatter across a dark backdrop in the same instant.
Bring back next class:
- The
.sb3file. - Your answer to: "You changed only the call to draw star (), never the define. List three other things in your project that could become My Blocks if you used them more than once."
Heads up for next class: SCR-L03-20 starts Cluster D — Cloning. You'll meet the idea of a clone: a temporary copy of a sprite that runs its own scripts. Think raindrops, bullets, falling apples — anything you'd otherwise need fifty sprites for.