- Learnt28 min · rainbow colour, a white eraser, stamp, a tool variable
- Basic25 min · three tools on 1, 2 and 3
- Challenge 1–327 min · say the tool, a stamp tool, a spray can
- Extrabonus · a straight-line tool
Review — Sketch Pad II 5 min
set pen color to [#D400AB]andset pen size to (8)change the next line.- Every sprite has its own pen. Buttons send a message; the pencil changes its own pen.
- The
colourvariable carries the colour code.
Quick-fire
Your pencil’s pen is pink. Then a script runs set pen color to [#FFFFFF]. You draw over a pink line. What do you see?
Reveal the answer
The pink line disappears where you drew. White on white paper looks like nothing at all. You have just built an eraser.
Today’s Topic 3 min
change pen (color v) by (2)— a rainbow line- An eraser is a white pen
stamp— printing the sprite onto the paper- A
toolvariable that holds a word
Learning outcome
By the end of this lesson you will be able to:
- Make the pen change colour as it draws.
- Stamp a copy of a sprite onto the Stage.
- Use one variable to switch between tools.
Learnt — one pencil, many tools 28 min
1 · A rainbow line
The pen has a colour number as well as a colour code. It runs from 0 to 100, round the rainbow: red, orange, yellow, green, blue, purple, and back to red.
when flag clicked
erase all
set pen color to [#FF0000]
set pen size to (10)
pen down
repeat (80)
change x by (5)
change y by (pick random (-6) to (6))
change pen (color v) by (2)
end
pen up
How to use this: Click the green flag to start it. Nothing else to press — watch the line change colour as it grows.
Past 100 the number goes back round to 0. So the rainbow never runs out.
2 · An eraser is a white pen
Scratch has no rub-out block. But the paper is white. A fat white pen over a line hides it.
set pen color to [#FFFFFF]
set pen size to (30)
How to use this: Click the green flag to start it. Nothing else to press — watch the middle of the line vanish.
3 · Stamp
stamp prints the sprite’s costume onto the paper, like a rubber stamp. The sprite can then move on. The print stays until erase all.
when flag clicked
erase all
go to x: (-180) y: (-20)
repeat (7)
stamp
wait (0.3) seconds
change x by (60)
change [color v] effect by (25)
end
How to use this: Click the green flag to start it. Nothing else to press — watch the row of stars appear.
4 · A tool variable
Now the pencil can be a pencil, a rainbow brush or an eraser. It needs to know which. A variable called tool holds the word.
when [2 v] key pressed
set [tool v] to [rainbow]
set pen size to (8)
if <(tool) = [rainbow]> then
change pen (color v) by (3)
end
pen down
You used the same idea in Level 3, when a state variable held menu or play.
Basic — three tools 25 min
Open your sketch pad from last lesson.
Step 1 — the variable
- Make a variable called
tool, for all sprites. Tick it so it shows. - In the pencil’s green-flag script, add
set [tool v] to [pencil].
Step 2 — three keys
- Key 1:
set [tool v] to [pencil],set pen size to (4),set pen color to (colour). - Key 2:
set [tool v] to [rainbow],set pen size to (8). - Key 3:
set [tool v] to [eraser],set pen size to (24),set pen color to [#FFFFFF].
Step 3 — the loop asks
- Find the pen down inside your drawing loop.
- Just above it, add
if <(tool) = [rainbow]> thenholdingchange pen (color v) by (3).
Step 4 — a colour click means the pencil
- In
when I receive [new colour v], addset [tool v] to [pencil]andset pen size to (4). - Test: press 3, rub something out, then click a ball. You are drawing again.
when flag clicked
go to [back v] layer
erase all
set [colour v] to [#4C4CFF]
set [tool v] to [pencil]
set pen color to (colour)
set pen size to (4)
forever
go to [mouse-pointer v]
if <<mouse down?> and <(mouse y) < (130)>> then
if <(tool) = [rainbow]> then
change pen (color v) by (3)
end
pen down
else
pen up
end
end
when [3 v] key pressed
set [tool v] to [eraser]
set pen size to (24)
set pen color to [#FFFFFF]
How to use this: Click the green flag, then click the stage once. Press 1, 2 or 3 to pick a tool, then hold the mouse button down and drag. Click a ball to pick a colour.
After the eraser, the pencil draws white.
Key 1 is missing set pen color to (colour). The pen stays white until something changes it back.
The rainbow is all one colour.
The change is outside the if, or the word in the if is not exactly rainbow. Check the spelling in both places.
Say the tool
- Every time the tool changes, the pencil says its name for 1 second.
- This works for the keys and for a click on a ball.
How to use this: Click the green flag, then click the stage once. Press 1, 2 or 3, or click a ball, and watch the Pencil.
Teacher reveal
Add say (tool) for (1) seconds at the end of all four scripts. Saying the variable, not the word, means one block works everywhere.
A stamp tool
- Key 4 picks the stamp tool. The pencil turns into a star.
- Each click on the paper prints one star.
- Holding the button down still prints only one.
- Keys 1, 2 and 3 turn it back into a pencil.
How to use this: Click the green flag, then click the stage once and press 4. Click on the stage to stamp stars. Press 1 to go back to the pencil.
Teacher reveal
Add a star costume to the pencil. In the loop, before the rainbow check:
if <(tool) = [stamp]> then
stamp
wait until <not <mouse down?>>
else
pen down
end
The wait until <not <mouse down?>> is what stops the smear. Key 4 also does pen up and switches costume.
A spray can
- Key 5 picks the spray can.
- While you hold the button, little dots land near the mouse, not on it.
- No line joins the dots.
- It uses the colour you picked.
How to use this: Click the green flag, then click the stage once and press 5. Hold the mouse button down and drag to spray.
Teacher reveal
if <(tool) = [spray]> then
pen up
repeat (6)
go to x: ((mouse x) + (pick random (-20) to (20))) y: ((mouse y) + (pick random (-20) to (20)))
pen down
pen up
end
end
Pen down then pen up in the same place draws one dot. The pen up before each jump is what stops the dots joining.
A straight-line tool
Hands are wobbly. Give the app a ruler.
- Key 6 picks the line tool.
- Press the button, drag, and let go.
- One straight line appears, from where you pressed to where you let go.
- Nothing is drawn while you are dragging.
How to use this: Click the green flag, then click the stage once and press 6. Press the mouse button, drag, and let go.
Teacher reveal
if <(tool) = [line]> then
pen up
set [start x v] to (mouse x)
set [start y v] to (mouse y)
wait until <not <mouse down?>>
go to x: (start x) y: (start y)
pen down
go to [mouse-pointer v]
pen up
end
Summary 5 min
change pen (color v) by (2)walks the colour round the rainbow, 0 to 100.- An eraser is a white pen on white paper.
stampprints the costume onto the paper.- One variable holding a word decides what a drag does.
- Colour number
- The pen’s colour as a number from 0 to 100, round the rainbow.
- Stamp
- A print of the sprite’s costume left on the Stage.
- Tool
- What a drag does right now: draw, rainbow, erase or stamp.
Hand in
Save your sketch pad. Next lesson a second pencil copies every move you make, and you get the app ready to share.