Learning Goals 3 min
By the end of this lesson you will be able to:
- Use set pen color to () (the colour-picker version) to pick any colour for the pen before you start drawing.
- Use set pen size to () to choose how thick the line is, and change pen size by () to grow or shrink it while drawing.
- Build a rainbow trail by putting change pen color by (2) inside a loop — every step cycles the hue, every step adds a new colour to the line.
Warm-Up — the boring blue line 7 min
Here's the horizontal-line drawing from SCR-L04-07. One small change has been added at the end: a wait so we have time to look.
when flag clicked
erase all
go to x: (-200) y: (0)
pen down
move (300) steps
pen up
Click the flag (mentally). The cat draws the line. Now look at it closely — what colour is the line, and how thick is it?
Reveal the answer
The line is a thin sky-blue, roughly 1 pixel thick. Those are Scratch's default pen settings — the pen always starts as a thin blue marker unless you tell it otherwise. Every project you've ever drawn with the Pen extension begins this way.
Default is fine for a first drawing. But a kolam pattern wants gold, a danger zone wants red, a fat highlighter wants size 20. Today we learn the four blocks that let you choose.
Today's question: how do we make the cat draw any colour, at any thickness, and change it mid-drawing?
New Concept — four blocks for one pen 15 min
The Pen extension gives you two pen properties you can change: colour and size. Each property has two blocks — one to set it to a specific value, and one to change it by a small amount each time. That's the same set-vs-change pattern you've already met for variables.
Set pen colour — the colour picker
set pen color to [#FF0000]
Click the coloured square on the block. A little picker pops up with three sliders — Color (the hue, 0 to 100), Saturation (how vivid, 0 to 100), and Brightness (how light, 0 to 100). There's also an eyedropper button at the bottom: click it, then click anywhere on the Stage or Scratch window to copy that colour into the pen.
The eyedropper is the secret weapon. Want the pen to match the cat's orange fur? Click the eyedropper, click the cat. Done.
Change pen colour — the rainbow trick
change pen color by (2)
This one is different. The number isn't a colour — it's a step around the colour wheel. Pen colour is internally a number from 0 to 200, where 0 and 200 are both red, 70 is bright green, 130 is blue, and so on around the wheel. change pen color by (2) nudges that number forward by 2. If you keep nudging, the colour cycles through the whole rainbow and starts over.
Combine this with a loop and you get the most-loved Pen effect in Scratch — a rainbow trail.
Set pen size — pixels wide
set pen size to (5)
Size is measured in pixels. 1 is a thin pencil, 5 is a felt-tip, 20 is a highlighter, 50 is a paint roller. The maximum is 1200 (which fills the Stage). For most kolam-style projects, 3 to 8 looks best.
Change pen size — growing strokes
change pen size by (1)
The rainbow stack
Here's where it all comes together. A loop, a tiny move, a tiny colour change. Run it and the cat draws a rainbow.
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#FF0000]
set pen size to (5)
pen down
repeat (100)
move (4) steps
change pen color by (2)
end
pen up
The maths: 100 × 4 = 400 steps total (slightly off the right edge — perfect for a Stage-wide rainbow). And 100 × 2 = 200, which is exactly one full lap around the colour wheel. The line starts red, fades through orange, yellow, green, blue, purple, and ends back at red.
Worked Example — the rainbow line 12 min
Open Scratch. Pen extension already added. We're going to build the rainbow stack from the concept section in eight steps, so you understand exactly why each block is there.
Step 1 — Start fresh
New project. Default cat. Drag the cat to roughly the middle of the Stage to start.
Step 2 — Drop the hat and wipe the Stage
From Events: when ⚑ clicked. From Pen: erase all right under it. Same pattern as last lesson.
Step 3 — Jump to the start
From Motion: go to x: (-200) y: (0). We want the rainbow to start on the left side of the Stage.
Step 4 — Pick a starting colour
From Pen: set pen color to [#FF0000]. Click the swatch, drag the Color slider all the way to the left (0) — that's pure red. Saturation 100, Brightness 100. The block's swatch turns bright red.
Step 5 — Pick a thickness
From Pen: set pen size to (5). Thick enough to be obvious, thin enough that the line doesn't smudge.
Step 6 — Drop the pen, then start the loop
From Pen: pen down. From Control: repeat (100). The pen-down sits outside the loop — you only need to drop the pen once. The loop is what runs the move and the colour-change many times.
Step 7 — Inside the loop: move a tiny bit, change colour a tiny bit
Inside the repeat: move (4) steps followed by change pen color by (2). Small move so the colour can change smoothly. Small colour change so the rainbow is gradual, not stripey.
Step 8 — Lift the pen at the end
After the loop closes: pen up. Same hygiene reason as last lesson — leave the pen lifted when you're done.
Click the flag. The cat slides from left to right, leaving a thick rainbow trail behind it that cycles all the way through the spectrum. That's it. Eleven blocks, one full rainbow.
The full assembled stack
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#FF0000]
set pen size to (5)
pen down
repeat (100)
move (4) steps
change pen color by (2)
end
pen up
What you just built: the same trick that draws every animated wallpaper, neon spirograph, and rainbow snake on the Scratch homepage. A loop, a tiny move, a tiny colour change. Tomorrow you'll use the same loop to draw triangles and squares — different geometry, same skeleton.
Try It Yourself — three colour drills 15 min
Goal: Draw a thick green horizontal line, 10 pixels thick. No rainbow, no loop — just one solid stroke. Use the colour picker's eyedropper to pick a specific green if you like.
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#00CC00]
set pen size to (10)
pen down
move (400) steps
pen up
Think: Notice that set pen color to () and set pen size to () both come before pen down. The pen's "ink" has to be loaded before you start drawing — otherwise the first part of your line is in the old colour from last project.
Goal: Draw a line whose thickness grows from thin to fat as the cat moves across the Stage. Start at size 1; add 1 to the size at every step of the loop.
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#0066FF]
set pen size to (1)
pen down
repeat (50)
move (8) steps
change pen size by (1)
end
pen up
Think: After 50 repeats, the size is 1 + 50 = 51. That's pretty thick. Try replacing change pen size by (1) with change pen size by (-1) and starting at size 51 — now the line tapers down like a feather. The change-by pattern works in both directions.
Goal: Make a rainbow trail that also changes size. The line should start thin and red, grow thick and rainbow-y as the cat moves, then thin out again. Use a single loop with both colour and size changing.
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#FF0000]
set pen size to (1)
pen down
repeat (50)
move (4) steps
change pen color by (2)
change pen size by (1)
end
repeat (50)
move (4) steps
change pen color by (2)
change pen size by (-1)
end
pen up
Think: Two separate loops, back to back. The first grows the line (change-by +1); the second shrinks it (change-by −1). Notice the colour cycle (change-by 2) happens in both loops, so the rainbow keeps flowing the whole way across. This is the bumblebee-trail effect that Scratch beginners always discover and love.
Mini-Challenge — the stripey rainbow 5 min
"Arif's broken rainbow"
Arif tried to draw the classic rainbow line, but his looks stripey — five thick blocks of solid colour, not a smooth gradient. He shows you his stack:
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#FF0000]
set pen size to (5)
pen down
repeat (5)
move (80) steps
change pen color by (40)
end
pen up
The line still ends in roughly the same place, and the colours still cycle through the rainbow once — but the effect is all wrong. What's the underlying rule, and how do you fix Arif's stack?
Reveal one valid solution
The colour changes happen between moves, not during them. Each iteration moves 80 steps in one solid colour, then changes colour, then moves another 80 in a new solid colour. Big moves and big colour jumps mean each chunk of line is one colour — five chunks, five stripes.
For a smooth rainbow you need many short steps and many tiny colour changes, so that each painted pixel is a slightly different hue from the one before. Same total distance, same total colour cycle — just split into many small slices instead of five chunky ones.
when flag clicked
erase all
go to x: (-200) y: (0)
set pen color to [#FF0000]
set pen size to (5)
pen down
repeat (100)
move (4) steps
change pen color by (2)
end
pen up
Same total move (100 × 4 = 400 steps, same as 5 × 80). Same total colour cycle (100 × 2 = 200, same as 5 × 40). The maths is identical — the rainbow looks completely different. The lesson: smoothness depends on step size, not on totals.
Recap 3 min
You now have four blocks to customise the pen. set pen color to () uses a colour picker (with an eyedropper); change pen color by () uses a number that steps around the colour wheel (0–200). set pen size to () sets pixel thickness; change pen size by () grows or shrinks it. The rainbow trick is just change pen color by (2) inside a loop with many small moves. The same skeleton draws gradients, fat-to-thin tapers, and pulsing strokes.
- Hue
- The "what colour" part of a colour — red, orange, yellow, green, blue, purple. change pen color by () moves the pen's hue around a wheel from 0 to 200 and back.
- Colour picker
- The small panel that pops up when you click the swatch on set pen color to (). Three sliders (Color, Saturation, Brightness) plus an eyedropper.
- Eyedropper
- The pipette button at the bottom of the colour picker. Click it, then click anywhere on the screen, and the pen colour becomes whatever pixel you clicked.
- Pen size
- The thickness of the drawn line in pixels. Default 1, maximum 1200. Most drawings look best between 3 and 10.
- Set vs change
- Set blocks jump to a specific value. Change blocks nudge by an amount. Both colour and size come in set/change pairs — same pattern you saw with variables in L3.
Homework 2 min
The Three-Stripe Flag. Draw three thick horizontal lines stacked on top of each other — red on top, white in the middle, blue at the bottom. Like a simple flag.
- Start with when ⚑ clicked and erase all.
- set pen size to (40) so the stripes are nice and chunky.
- Top stripe: go to x: (-200) y: (60), set pen color to [#FF0000] (red), pen down, go to x: (200) y: (60), pen up.
- Middle stripe: jump to go to x: (-200) y: (0), set colour to white (use the picker — slide Brightness to 100 and Saturation to 0), pen down, draw to go to x: (200) y: (0), pen up.
- Bottom stripe: same trick at y: −60, with blue.
Save as HW-L4-08-Flag.sb3. Click the flag (the green one — not your drawing!). You should see three clean stripes, well separated, no diagonals.
Bring back next class:
- The
.sb3file. - Your answer to: "Why does set pen color to () have to come before pen down for each stripe? What goes wrong if you swap them?"
Heads up for next class: SCR-L04-09 teaches the polygon formula — repeat N times: move then turn (360 ÷ N). Same loop you used for the rainbow, but now the cat turns on each step instead of going straight. The result is shapes.