Print

Snap! Sprite Sizer

Make the turtle sprite bigger or smaller with the distance sensor

Programming Language

Snap!

Subjects

Programming Tutorials

Grades

4-5, 6-8

Free Teacher Materials

Get Access

Objective & Learning Goals

  • UseĀ sensors to control Snap! graphics
  • Scaling with math operators

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 turtle (arrow) 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 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.
  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 arrow should get larger when the object is closer.
  7. Now let’s make the size change more noticeably by making the arrow three times larger. Add a multiplication block to do this.
  8. Run the program and the arrow should be much larger when your hand is close.