[LinuxFocus-icon]
<--  | Map  | Index  | Search

News | Archives | Links | About LF
This document is available in: English  Castellano  Deutsch  

[Alex]
by Alexander Langer
<lf(at)kuxi.de>

About the author:
I'm using Linux since 1993. Coming from the Amiga, I like that you can get the source code for everything and find out how others do it in their programs.
Content:

 

Simple Animation

[Illustration]

Abstract:

[open
mouth]

Creating a simple animation is fun and easy, for children and adults alike. Possible types of animation include simple object animation, Monty Python-style animations, time-lapse films, clay animation a'la Wallace&Grommit and many more.

In this article we will not create a full film. Using a very simple example you will lean the basic techniques. Just enough to start your own movie ;-).

Note: The picture on the right and the little dot above are animated. You need to enable gif-animation if you want to see them in your browser.

_________________ _________________ _________________

 

Overview

Creating an animation is a three-step process: First, you make up your mind what you want to do. This can be as simple as asking the kids to bring a toy car and some figures and starting right away with making a car-accident movie. Or you do it like professional animators and design a story-board with detailed plans and sketches. A good idea and a well-thought out story is usually more important than high-quality or expensive equipment.

Regardless how you plan it, the next step is to acquire the single frames of the animation. Optionally you post-process them or add frames with text, just like in the old Stan-and-Ollie movies.

Last, you merge the single frames into a movie.  

Required Hard- and Software

The images can come from multiple sources: If you want to acquire the images from an external source (one of the first three in the list above) I assume you have working software to do that. Besides that, we will use the program mencoder from the mplayer (www.mplayerhq.hu) package to produce the movie. It is powerful software, is probably already installed on your computer, and with mplayer you have a program to view the film.

To edit the frames, you can use Gimp or any other painting program.
ImageMagick (www.imagemagick.org), the Swiss Army Knife of programs to convert and display images, is very useful to display and create animations.  

A First Animation

If you have a webcam or digital camera, place it on the table and put something in front of it. This "something" can be an apple, a glass, or just your hand. My children had fun with a Playmobil car and figures, creating the car-accident movie mentioned before. Shoot a series of pictures and move the object a little between the individual pictures. 10-20 pictures is enough for your first film.

If you don't have a camera, no problem, we'll make a "jumping-dot" animation. Start Gimp and select File->New. Click "OK" to get a default 256x256 image with white background. Select the brush tool in the main window and click somewhere in the lower left area of the image to produce a dot. Right-click into the image, select File->SaveAs and save the image as "0001.jpg" into an empty directory. Just click "ok" in the JPEG-options screen. This is the first frame. Let's say we want 10 frames, thus repeat the following 9 times:

  1. move the mouse-pointer close to the current dot. If you place the dots with even spacing from frame to frame, the motion will look linear. For a jumping ball its more realistic to reduce the spacing when the dot is at the upper part of its trajectory.
  2. press CTRL-z to remove the current dot (CTRL-z is undo)
  3. click to produce the new dot at the new position
  4. right-click, select File->SaveAs and save as 0002.jpg etc.
    Tip: Tear off the "File" menu by selecting the dashed line from the "File" menu. This will leave the File menu permanently open on the desktop and you can just click on "Save As...".

You should now have something like this:
[frame1] [frame2] [frame3] [frame4] [frame5] [frame6] [frame7] [frame8] [frame9]

Now we create the movie:

$ mencoder 'mf://*.jpg' -mf type=jpg:fps=4 -ovc copy -oac copy -o output.avi
The parameter "fps" specifies the "frames per second" value. Lower numbers mean less work for you, but a more jerky animation.

To watch your masterpiece, type:

$ mplayer output.avi
If you want to experiment with different frame rates you can do that with mplayer's "-fps" option, for example to force 10 frames per second, use "-fps 10". It's not necessary to encode the animation again with a different frame rate unless you want to give it to somebody else.

Especially for short clips it's often handy to use the "-loop" option, for example "-loop 10". This will play the clip ten times.

Alternatively to using mencoder/mplayer, with the animate program from the ImageMagick you can preview the clip:

$ animate *.jpg
It plays the clip continuously. If you left-click into the animation a menu will open. You can use the Space and Backspace keys to single-step through the animation (the filename of the current frame is shown in the title bar of the window, useful if you want to touch up a single frame). To change the speed of the animation, use the "<" and ">" keys.  

Monty Python Style

For a Monty Python style animation, take a photograph of a face. If you don't have a picture, take one from the web. It should show the face from the front, chin well visible. Load it into Gimp and click on the Lasso-tool. Select the chin and the lower lip, you will have a more or less rectangular selection that follows the chin shape at the bottom part of the selection. Press CTRL-c to copy the selection. Press CTRL-y to remove the selection. Now the clipboard contains a chin that you can move up and down, but to create a better illusion, draw the mouth black, over-painting the lower lip and the region below.

Now press CTRL-v and select the Move-tool (its icon is arrows in all four directions). Move the chin where originally was. Save the picture as 0001.img, just as you did with the jumping dot, click on "Export" when Gimp complains that JPEG cannot handle transparency. Move the chin a little down and SaveAs 0002.jpg. Continue until you have all the frames. Then encode with mencoder. You'll get bonus points for lip-sync to music or a speech audio track.

If you want to encode to an animated GIF (like the image at the top of this article), ImageMagick's convert program does that:

$ convert -delay 20 *.jpg out.gif
The "-delay" option is in 1/100th of a second, thus 20 equals 5 frames per second. By the way, you can see the single frames in the animated GIF with "identify":
$ identify out.gif"
out.gif[0] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[1] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[2] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[3] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[4] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[5] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[6] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[7] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[8] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[9] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
out.gif[10] GIF 152x104+0+0 PseudoClass 256c 8-bit 201.1k 0.0u 0:01
 

Time-Lapse Movies

Time-lapse animations are easy to create yet can be very interesting. And you don't have much worries about a script or story. All you have to do is setting up your computer to take pictures in regular intervals. If you have a video4linux (v4l) -compatible camera, you may want to try vgrabbj (gecius.de/vgrabbj/). It can take pictures every x seconds and save them to files.

If you shoot automatically, you can afford the luxury of a high frame rate, as long as your free hard-disk space permits.

What to film?

I have not tried it myself, but if your baby has just been born, you could take a photo every x months from birth throughout its life. Ok, it will take a long time until you have a couple of frames, but the result should be quite nice. I would take real photographs and scan them because you can be sure that real photos will last many years, compared to file formats, media rotting and other problems.

If you decide to take pictures of your child growing, my conclusion is that 6 months should be often enough to get enough pictures without being too often to not do it. If your baby is born in summer, you can take birthday and Christmas photos :-) The other conclusion I had is to take the picture always so that 2m are shown in the photo, to have the same scale for all the photos. Otherwise you have to scale them yourself.  

Other Ideas

Figure out how to add audio to your animation. Even if you just make noise by tapping your feet, screeches, clicks etc. it makes the animation much more lively.

Re-do Pixar's Luxo Jr. (www.pixar.com/shorts/ljr/) with your desk lamp and a ball.

Let's say you want to add a balloon, to make a person or figure say something. Instead of using steps of "1" for the image names, use steps of "10" when you shoot the frames. Load the frame to which you want to add the balloon into Gimp. Draw the balloon and add the text. Save the frame and exit Gimp. Now, duplicate (copy the file) the frame 9 times, give them the numbers between the current and the next frame. If you have programmed BASIC during the 80ies you remember this technique :-) When you encode this, the frames with the balloon will be shown for a longer time, long enough that it's possible to read the text. With the same technique you can insert a new frame as they did in the silent movies at the beginning of the 20st century.

You will soon wish to be able to see the previous frame(s) overlaid over the live camera picture (called "onion skin"). With that you can better align the position of moving objects, improving the illusion of motion. The Gimp Animation Package looks promising for this purpose.  

Further Readings

 

Talkback form for this article

Every article has its own talkback page. On this page you can submit a comment or look at comments from other readers:




Webpages maintained by the LinuxFocus Editor team
© Alexander Langer
"some rights reserved" see linuxfocus.org/license/
http://www.LinuxFocus.org
Translation information:
en --> -- : Alexander Langer <lf(at)kuxi.de>

2004-10-15, generated by lfparser version 2.50