Animation Implementation
The aim is to handle the animation in as flexible a way as possible
and to do that we will attempt to use
image files where appropriate.
We will consider an animation as a sequence if
images which we cycle through at
a given rate.
Rather than having a single image that we replace each cycle,
we will break the animation down into smaller components.
(It might be easier for whoever creates the images to
do it using a sequence of complete images. However,
delivery of the images to the programmer should be as sequences
of sub-images.)
For instance, consider the
animation in the CLT lab
in which the population histogram is created from
the dataset.
Each of the observational units moves from the pool at the bottom left
of the screen along a path
to each of the different animation points
and then forks to go to the sampler and population histogram.
The sequences of sub-images are
- the observational unit moving. For example, we plan on having
a lemming or a person here which is seen walking, swinging its
arms,
- Data Entry person who types the value for the observation
at the keyboard and we see it coming up on the computer.
(Not the actual value necessarily),
- the transmission of the packets along the cable between the
computer and printer,
- The printer ejecting the printed page,
- the piece of paper as it moves between the printer and the photocopier,
- the photocopier,
- the sampler.
So, for each component,
we will have a sequence of images which animate that component.
So for example, something as simple as this type of flip-book
sequence will do the job.
0 0 0 0
\|/ |/ | \|
| /| /|\ |\
/ \ / \ / \ / \
When the particular component is to be animated
within the global animation, we simply cycle through the images
displaying one and pausing for the appropriate interval.
The phrases in bold in the sentence describing the
animation are what I think of
as the essential attributes for the class.
There are two types of animated components -
Moving and Fixed position.
Each is characterized by
- a sequence of images used to animate the component
- an interval between frames of the sub-animation
- a position in the picture
-
The moving components also have the following attributes
- the path along which they move
- a velocity
When moving an object from p0
to p1, we must restore whatever is underneath
it at p0 and draw the next image in the sequence
at p1.
We can do this in at least three ways.
- Complete Double Buffering
- We can keep an image of the entire static picture with no
moving components in memory. When we move a component,
we copy the rectangle it occupies
from the buffer onto the corresponding position on the
screen.
- Partial Double Buffering
- Instead of keeping the whole image, before we move a component
to a new point, we grab the rectangle it will occupy and
cache that so that we restore it before we move the component
to the next spot.
This is a better solution than the previous one since it
reduces the overall memory unless the number of moving
components is very large and also allows the
object that controls the component to cache the information
locally in the component itself. That might be an issue
when considering the threaded nature of the animation and
access to a global image.
- XOR
- This method relies on a feature of the graphics context.
Drawing can be done using a mode call XOR. This has the effect
that drawing an object in this mode once renders the object
and drawing it a second time, removes it restoring the
original object. Exactly what we want!
The only difficulty with this is that we still have to handle
resizing and the resulting repainting of the screen.
This is not complicated, just tedious.
This is approach is the one I favor.
Each approach relies on the premise that two moving components can never
overlap. In our animations this is a highly desirable constraint and
so is not a restriction.
Coordinates
When the animation is created by the designer, etc.
there is an implicit coordinate system established.
Each of the sub-components of an animation
is located relative to the other components
and ultimately to that global coordinate system.
So each animation scene has a natural or true
width and height. This is to be specified
in the description of the scene read by the program.
Scaling
When the scene is displayed in the card, it is allocated
space based on the size of the window and the other components.
The size of course need not be the same as the true size of the
scene as drawn by the designer.
So, we compute scale factors for the x
and y coordinates based on the actual dimensions
of the scene as displayed by the application
and the true size.
Specifically we divide each dimension of the
actual size by the corresponding dimension of the
true size and use these as scale factors for each and every
calculation done in this scene.
We want to make sure that the code that does this
scaling is in one place.
This can be done at in the AnimationPanel
class when it resizes the container.
This will take some more
thought.
HotSpots
Each object should be assigned a point - (x,y) -
which identifies the position at which
the moving component will "dock"
so that the "within component" animation
can start.
This might be the center of the object or a corner.
The point is specified in the coordinates
of the sub-component which has its origin
at the top left corner and increases
to the East and South. (Sorry!)
If this is not specified, the center of the object
will be assumed. However, we can change this in the
code easily.
Similarly, we can change the coordinate direction
to make it increase in a northerly direction.
Interval/Delay
The delay between cycles is constant and will be read
from the files describing the animation.
Programmed Animation (Sub-)Components
Programmed animation components are also described
by the same attributes as the external image
animation components.
The input file specifies the bounding box of each of these
components using some agreed upon name.
See the example below.
From the programmer's point of view, each of these
programmed animations must extend the class
ImageItem or some descendant of that class.
Then, rather than cycling through a set of images
loaded from disk, the program
either draws the new scene dynamically
or/and
draws the images dynamically a single time and
copies them to the relevant spot
later.
It is probably less work to redraw the image each time
since we have to arrange to have the scene drawn at least once.
Caching would require another, however simple, mechanism.
We should probably start with this simpler approach and
worry about performance at a later stage if necessary.
Image Specification File Format
The input file for an animation amounts to
a scene description and the parameters for the
dynamic component.
The file is broken into 3 sections.
The first is the general section which defines the global
parameters for the animation.
The second section defines the fixed nodes or components in
the animation that the moving objects travel between.
The third section defines the paths between the
different components.
General or global component parameters are specified as
name: value
Elements in the second and third sections are in the form
of stanzas. They are introduced
by
the #! modifier and the
stanza type (e.g. Component or Path).
Parameters within a stanza use the name: value
scheme.
The recognized parameters for the different sections/stanzas are
given below.
Note that any of the parameters for a stanza
can be specified in the general/global section also and
will be applied to all the relevant stanzas
in the scene. However, a stanza can provide a value to override
the global value.
Tags for Animation Input File
| sampleSize |
number of lemmings that are to pass through the animation.
This might come from elsewhere in the lab.
|
| background | the name of a file that coun be located
in the usual generic way which will be drawn as the background
for the entire animation. |
| color | the background color to paint the animation area. |
| size |
width and height in which the remainder of the
coordinates are specified.
At present, (0,0) is at the top-left corner.
No negative values in the global coordinates are allowed
- only for hotspots for sub-components expressed as an
offset.
Any negative values are clipped or set to 0. I don't know
yet.
|
| simultaneous |
the maximum number of observational
units passing through the animation at any one time
simultaneously. The program
may limit this number if it is too large as
there may be a thread per unit.
|
| movingComponent |
the name of the default moving component.
The details of the object are specified in future stanzas.
If no paths are specified this is used throughout.
The attributes for this object are used as defaults
for those not specified for any other moving component.
|
| Component section |
| name |
name to assign to component for use in specifying paths.
|
| bbox |
rectangle defining the position and dimensions of the
component. Specified as a comma separated list
of values x, y, width, height.
The width and height can be omitted and will be computed
from the image.
|
| inHotspot |
a comma separated list in the order x,y for the point to which
the moving item heads along the path between components. |
| outHotspot |
a comma separated list in the order x,y for the point from which
the moving item leaves the component. |
| background |
the color to paint this component. Default is to leave as is
allowing transparent images to do the right thing.
|
|---|
| activeBackground |
the color to paint this component when it is active. Default is to leave as is
allowing transparent images to do the right thing.
|
|---|
| images |
comma separated list of image names. For the moment,
explicitly list these (e.g. image1, image2,image3,image4,...).
However, in the future, we might support something like
image1-4. |
| interval |
delay between successive frames of the animation in milliseconds.
Do you want nano-seconds? |
| ... |
optional attributes such as color, font, etc. that might
be used to override the default settings.
This is especially useful for programmed animations.
|
|
| Paths |
This part of the file consists of stanzas defining the paths
between the different sub-components. Each path is specified
using a subset of the resources described
| components |
a comma separated pairs of strings identifying the
source and target components. If only one string is
specified, that is the target. |
| delay |
interval between successive steps taken along this path.
Specified in milliseconds |
| images |
image sequence same as above |
| type |
this specifies the type of path.
The current options are "linear"
"bezier" or "expanded". Default is "linear"
and the end points can be omitted and are taken
from the hotspots of the components.
|
| points |
a comma separated list of points
taken as
x0,y0,x1,y1,x2,y2,...
which specify the points associated with
the type of curve.
If the type is "linear", no points are needed
and this property should be omitted for this path.
The coordinates are relative to the global coordinate system of
the scene. If this causes problems we can provide other ways of
specifying
them relative to the source and target components' coordinates.
Default is omitted.
|
| steps |
the number of steps to take along this path. The length of the path
between the components is divided into equally spaced steps.
The larger this value, the smaller the size of each step.
|
|---|
|
show
|
true or false indicating whether the path should be
drawn on the screen. This helps in the Design of Experiments and
the CLT. Default is false |
|
Example
The different components have been quickly marked
on the image.
(Note that we have removed the filing cabinet and inserted
the sampler that is used in several of the other labs.)
The blue dots indicate a hotspot for entering the object.
A green blob indicates a hotspot for leaving the component.
size: 569,297
simultaneous: 4
#!Component
# This is special
name: population
bbox: 5,207,250,88
# at the top of the box & in the middle
outHotspot: 130,210
# no images as we use the lemmings in the pool.
# and no interval since it is under program control.L
#!Component
name: data entry
bbox: 5,125,86,73
# Note that all the images must be specified on a single line
images: data_entry,data_entry[1-6]
interval: 300
inHotspot: 85,188
outHotspot: 91,162
#!Component
name: printer
bbox: 233,69,52,47
images: printer, printer[1-9]
interval:200
inHotspot: 232,91
outHotspot: 285,94
#!Component
name: copier
bbox: 355,28,89,75
images: copier, copier[1-12]
interval: 100
inHotspot: 355,60
outHotspot: 447,67
#!Component
name: sampler
bbox: 465,61,101,89
# rest of details are handled by program
#!Component
name: histogram
bbox: 376,189,186,101
#!Path
# Note default is not to show
components: population,data entry
delay: 110
images: lemming[1-10]
#!Path
components: data entry, printer
delay: 100
images: pulse[1-4]
show: true
#!Path
components: printer,copier
delay: 100
images: pulse[1-4]
show: true
#!Path
components: copier,sampler
delay: 100
images: paper[1-4]
#!Path
components: copier,histogram
delay: 100
images: paper[1-4]
The Classes
In this section we design the toplevel
classes that I believe can be shared across
all the labs that use animation.
These are realizations of the attributes and methods
we have above.
ImageSequence
Each animation component is displayed as a sequence of images.
AnimatedImageSequence
AnimationSceneItem
MovingAnimationItem
Path
BezierPath
LinearPath
ExpandedPath
AnimationScene
This class
AnimationPanel
This class extends Panel and
Duncan Temple Lang<duncan@cm.bell-labs.com>
Last modified: Mon Jun 30 10:50:24 1997