Animate Help

Animate Help

What's really going on in the AnimateCanvas?
Think of the AnimateCanvas as maintaining a set of snapshots of your drawing, taken as it changes over time. Each snapshot is labelled with the time at which it was taken. The AnimateCanvas knows how to maintain this list by adding in new snapshots and updating old snapshots. It also knows how to interpolate between snapshots to figure out what your picture looks like as it changes from one snapshot to another.

How does the AnimateCanvas interpolate between snapshots?
The _shapeList data stucture in AnimateCanvas is an array of InterpPolygons (LinInterpPolygons, to be exact). An InterpPolygon is a polygon whose vertices change in position as a function of time. Think of it as maintaining a set of snapshots of a single polygon and knowing how to interpolate between these snapshots. How does it do this? An InterpPolygon keeps an array of Interpolators to keep track of the x-positions of each vertex and an array of Interpolators to keep track of the y-positions of each vertex. If an InterpPolygon has 10 vertices, it then has two Interpolator arrays, each of size 10. See how this relates to an ordinary polygon:
 
an ordinary polygon:
  double[] _xs;
double[] _ys;
an interpolating polygon:
  Interpolator[] _xs;
Interpolator[] _ys;

How does an InterpPolygon know how to interpolate between snapshots, given a particular time?
An Interpolator knows how to return a value at a particular time (or will, once you fill in LinearInterpolator::getValue). An InterpPolygon has an Interpolator for the x-position of each vertex and an Interpolator of the y-position of each vertex. So, it can get a set of x and y-positions for the vertices at any particular time. Voilà, a polygon! This is what you need to implement in InterpPolygon::shapeAtTime().

How does an InterpPolygon know how to update or add a new snapshot at a particular time?
An Interpolator knows how to add a new InterpStep (a time and value at that time) and how to update an existing InterpStep. (That's already in the code. Look in Interpolator::addStep.) What does a snapshot consist of? It consists of an array of x and an array of y-values representing the positions of each vertex at a particular time. We know that InterpPolygon has an array of Interpolators for the x-positions and an array of Interpolators for the y-positions of the vertices. So, it can just add new interpolation steps for the x-position and for the y-position of each vertex. This is what you need to implement in InterpPolygon::addPoly().

How does the animation display?
The AnimateCanvas knows when the animation starts, when it ends, and how often it should display a new frame. It also has an array of objects (InterpPolygons) that know how to return a DrawableShape for any value of time. A DrawableShape is a shape that knows how to draw itself. So the AnimateCanvas has everything it needs to loop through some set of times, drawing sets of shapes representing the state of your animated drawing at each point in time. This is what you need to implement in AnimateCanvas::run().

Note that AnimateCanvas is set up to do double-buffering. Look in DrawCanvas::paint() to see how to properly use this.


jpower@cs.washington.edu
Last modified: Wed Feb 4 12:12:58 PST 1998