Week 2 · Unit 1: Making programs clear · 3 lessons
3
Reset the size
Computing 3: Unit 1, pp. 8–27
GoalUse the set size block to put a sprite back to its normal size every time the program starts.
New words
size · how big a sprite looks; a new sprite has size 100change size by · adds to (or takes away from) the size the sprite has nowset size to · gives the sprite exactly that size, whatever it was before
Explanation
Some programs make a sprite bigger or smaller. “change size by (15)” adds 15 to the size the sprite has now. Click the flag again and it adds 15 more, so the sprite keeps growing. “set size to (100) %” is different. It makes the size exactly 100, whatever it was before. Most new sprites start at size 100. Put “set size to (100) %” just after the hat block, together with the go to block. Then every run starts in the same way.
Worked examples
Click
No reset
With reset
1st
145
145
2nd
190
145
3rd
235
145
A sunflower sprite starts at size 100 and the program adds 15 three times, which is 45 in all. Look at the size after each click. Without a reset it grows every time. With the reset it is always 145.
“set size to” can use any number. Size 100 is the normal size. Size 50 makes the sprite half as big. Size 150 makes it one and a half times as big.
Put the resets straight after the hat block. Then the action blocks follow. The wait lets us see the start before the sprite starts to grow.
Class activity
Paper program (with a friend): use a sheet of paper for a score pad. The sprite starts at size 100. Read the program “change size by 20, change size by 20” and write the size after each click, with no reset: 140, 180, 220. Then add the card “set size to 100” at the start and run it again. What is the size after each click now?
Practice
1
A sprite starts at size 100. The program adds 5 four times. It is run 3 times with no reset. What size is the sprite at the end?
160. Each run adds 20: 100 + 20 + 20 + 20 = 160.
2
Now the block “set size to (100) %” is added after the hat block. What size is the sprite after 3 clicks?
120. Every click starts from 100 and adds 20.
3
The sprite must always finish at size 75. Which block goes in the empty slot so that it works every time?
set size to (100) %. Every run starts at 100, loses 25, and ends at 75.
4
What is the difference between “change size by (10)” and “set size to (10) %”?
Change size by (10) adds 10 to the size the sprite has now. Set size to (10) % makes the sprite exactly size 10, which is very small.