Lecture : Animation In Software
In the previous lecture:
In this lecture:
Getting your movie into the computer for digital playback
Record movie using a camera directly connected to a computer
|
Scan in handrawn images or cinefilm sequence
|
* Software like Adobe's Director & Flash (formerly Macromedia products) can also be used to create animation. These may be displayed in a web browser using plugins.
The Gap Minder Trendalyzer software animates statistical data to show how it changes over time. The software updates its screen at regular intervals corresponding to the intervals over which the data was collected (typically annual increments). In this way it displays a sequence of data points in space and time. |
|
Sorting algorithms can be coded with a visualisation to clarify the operation of the process. Every step of the sort is animated so that a viewer can follow the algorithm. |
|
Mathematical plotting software can show parametric equations using an animation that sweeps out a path over time. In this example, the circle rolls to the right and the markers along its radius sweep out the 2D dotted paths. Scientific visualization software can use animation to visualise movement and interactions of objects in 3D also. |
|
In computer games from Space Invaders to Spore, realtime computer graphics is used to animate entire virtual worlds with creatures, plants, buildings and a complex landscape. Players interactively navigate the landscape and the position of their avatar in the virtual world effects the way the animation on-screen is generated. |
|
Animation software can be used for educational exhibitions in museums or for interactive art works. Data about human movement in a space is gained using sensors. This influences the animation that is generated in realtime. Some of the exhibitions at the Melbourne Museum's V-ROOM operate in this way. |
Soot-Sprite animation demonstration
Java provides many useful tools for animation to be introuced into software.
The basic requirements of an animation program are:
Here is a simple example:
import java.awt.*; public class Animation extends JFrame implements ActionListener { int xCoordinates[] = { 250, 0 }; int yCoordinates[] = { 250, 250 }; int xTranslate = 0, yTranslate = 0; double angle = 0; double delAngle = Math.toRadians(137.5); // Fibonacci angle double radius = 20; int timerDelay = 10; // milliseconds
Timer timer;
public Animation ()
{
super ("Animation");
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e) { System.exit(0); } } ); setSize(500, 500); setVisible(true); // make a (Swing) timer that calls 'this' (object) to handle it timer = new Timer(timerDelay, this); timer.start(); } // Redraw the window and a make a soot-sprite picture in it public void paint(Graphics g) { // redraw the (blank) JFrame before redrawing the picture super.paint(g); // 1 in every 8 chances change the current x and y translations if (((int)(1011.0 * Math.random()) % 7) == 0) { xTranslate = (int) (5.0 * (0.5 - Math.random())); yTranslate = (int) (5.0 * (0.5 - Math.random())); } // perform the translation of the picture's centre xCoordinates[0] += xTranslate; yCoordinates[0] += yTranslate; // draw 20 radial lines emanating from the picture's centre for (int i=0; i<20; i++) { angle += delAngle; xCoordinates[1] = xCoordinates[0] + (int) (radius * Math.cos(angle)); yCoordinates[1] = yCoordinates[0] + (int) (radius * Math.sin(angle)); g.drawPolyline(xCoordinates, yCoordinates, 2); } } // The event to be called when the timer elapses public void actionPerformed(ActionEvent evt) { repaint(); } public static void main (String args[]) { Animation newAnimationWindow = new Animation(); } } |
Events and software responsiveness.
In between screen redraws, we usually want the software to continue to monitor the GUI for user-generated events (e.g. mouse clicks).
If we don't monitor user events, the software cannot respond to user actions!
Hence, we set the timer to trigger a redraw event, but we do not pause the program in between screen redraws.