Scratch Sprite Sizer
Make the cat sprite bigger or smaller with the distance sensor
Objective & Learning Goals
- Use sensors to control Scratch graphics
- Scaling with math operators
- Connect the distance sensor to sensor port 1.
- Plug the Hummingbird into your computer.
- We are going to make the value of the distance sensor determine the size of the cat sprite. To change the sprite’s size, go to the “Looks” category and move a “set size to” block to your screen.
- Next, attach a distance sensor block to the size block.
- This resizing should occur repeatedly, so place a forever loop around the size block.
- Run the code by clicking the loop.
The code works, but the cat gets smaller when your hand is closer to the sensor. Real objects get larger when they are closer, so it would make more sense if we made the cat get bigger when the distance detected that the object was closer.
- Add a subtraction block that calculates 105 minus the current sensor reading. 5 is the minimum value the distance sensor can produce, so 105 minus the sensor’s value will produce a size of at most 100%.
- Run the code again. This time the cat should get larger when the object is closer.
- Now let’s make the size change more noticeably by making the cat three times larger. Add a multiplication block to do this.
- Run the program and the cat should fill the screen when your hand is close.