Scratch Project 5: Sprite Sizer

Description: Make the cat sprite bigger or smaller with the distance sensor

Programming Concepts: using sensors to control scratch graphics

Materials: Hummingbird Controller, Distance Sensor

Difficulty: Intermediate

Approx. Time: 30 Minutes

Video:

Hummingbird setup

1. Connect the distance sensor to sensor port 1.

2. Plug the Hummingbird into your computer.

Programming steps

1. 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.

2. Next, attach a distance sensor block to the size block.

3. This resizing should occur repeatedly, so place a forever loop around the size block.

4. 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.

5. 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%.

6. Run the code again. This time the cat should get larger when the object is closer.

7. Now let's make the size change more noticeably by making the cat three times larger. Add a multiplication block to do this.

8. Run the program and the cat should fill the screen when your hand is close.

Example file

example-file-5-cat-sizer.sb2