We begin our study of Sound and Animation by looking at how these thingsare accomplished on a very basic (get it?) level. In fact all animations, from the most rudimentary flip pages to the most sophisticated Pixar type sequences, are done in exactly the same way: by quickly presenting a series of still images, called frames. On a TV, the rate is 30 fps (framesper second), and motion pictures operate at 24 fps. The reason this works is because of a property called persistence of vision. Whena human eye looks at an image, it is retained in the brain for a short period of time. When another image follows quickly, the brain turns itinto motion by perceiving a change in position of objects rather than as a simple change of image. This can be written algorithmically as
Loop Display an Image Wait a Bit
When creating animations via programming, typcially one does not wantto create a series of full frames that are shown in sequence; it is easierto program the position changes of individual objects (in fact something similar is done with computer video, such as Microsoft AVI files, where compression is accomplished by simply recording the changes from one frame to the next). The algorithm is this:
Loop Move to a new location Draw an object Wait a bit Erase the object
We will develop text-based animations for our purposes here.
Ok, now let's finally put this altogether into a programmed animation. Here is a very simple QBasic program that carries out a very simple animation:
'QBasic Animation #1 'Written by Peter Smith COLOR , 1 'Set the background color to BLUE CLS 'Clear the screen to this color COLOR 15 PRINT "Peter's First Animation" FOR p = 1 TO 79 GOSUB 1000 'Draw the object GOSUB 2000 'Wait a bit... GOSUB 3000 'Erase the object NEXT p COLOR 7 END 1000 'Draw the object LOCATE 6, p COLOR 14 PRINT CHR$(219) RETURN 2000 'Pause FOR t = 1 TO 500 NEXT t RETURN 3000 'Erase the object LOCATE 6, p COLOR 1 PRINT CHR$(219) RETURN