Stop-motion animation

What About the Webcam?

Besides using it as a tool to line up your shot, you could use the webcam feature of Scratch to take the photos manually, even with your Pi Camera, although that defeats the benefits of being able to program the camera.

If you don't have a Pi camera, then attaching a USB webcam to your Pi gives you camera capabilities to complete this project. However, you can't program the webcam in Scratch, so you have to interact with Scratch via the mouse to take photos. This method would go smoothly with two people: one to move the characters and one to take the shot.

Play the Movie

Once you've shot your movie, or at least a few frames, it's time to play it back. Figure 3 shows the scripts needed to play the movie. The basic idea is very simple. The script loops through each costume sequence in order, resulting in an animation. That's accomplished with the repeat until() and the next costume blocks. The other blocks in the script fine-tune the playback.

If you were to loop through all the costumes in succession, you would notice that the animation plays very quickly. To experiment with the animation speed, I added some additional blocks. The duration variable is recording the time, in seconds, of the animation so that you can see exactly how long the animation takes to playback. If you want to add a music track, this gives you an indication of how long that track should be.

The delay variable provides a user interface to set the delay between each costume display. When you make a new variable, Scratch automatically places a watcher on the stage. To turn the stage watcher into a slider, right-click on it and choose slider. Then, you can restrict the minimum and maximum amounts by choosing the set slider min and max option.

In the slider range dialog box that opens, specify a min value of 0.0 and a max value of 2.0. The decimal values are important because this will enable you to select decimal values with the slider. If you enter whole numbers for the min and max range, then you'll only be able to select whole numbers from the slider. As you experiment with the delay, you'll discover that the smaller delays create a better animation.

You can use the slider to select a delay, which is then inserted into the wait(delay) block in the script. This controls how long the script will wait after displaying the next costume. A higher delay value slows down the animation.

The delay is comparable to the frames per second (fps) value you might see as you learn more about stop-motion animation. Dedicated animation software will allow you to select how many frames (i.e., photos) you want to show each second. The higher the fps value, the smoother and more realistic the animation plays, but that also means you'll need more images to create the animation. For example, if you use 15fps, then a 10-second clip will require 150 photos (i.e., 15fps times 10 seconds).

Scratch is not movie editing software, but you can still apply the idea of frames per second to Scratch: More photos per second enables a faster display of the images, resulting in a smoother playback. Using the script in Figure 3 and a delay of 0 seconds, I can play my 72 images in 4.2 seconds. A delay of 0.1 takes 10.1 seconds to complete, whereas a 0.2-second delay takes 15.5 seconds. In my script, a smaller delay allows more images to be displayed per second.

Figure 3: The stop-motion playback scripts.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content