Snap! Sprite Sizer
Make the turtle sprite bigger or smaller with the distance sensor
Objective & Learning Goals
- Use sensors to control Snap! 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 turtle (arrow) 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 arrow 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 arrow get bigger when the distance sensor 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 arrow should get larger when the object is closer.
- Now let’s make the size change more noticeably by making the arrow three times larger. Add a multiplication block to do this.
- Run the program and the arrow should be much larger when your hand is close.