This example illustrates how to animate a sequence of sprites around a figure-8 curve (or infinity symbol), formally known as the Lemniscate of Bernoulli. The equation for the entire curve in rectangular coordinates (for arbitrary parameter, a) is given by
(x^2 + y^2)^2 = a^2(x^2 - y^2)
and in polar form by
r^2 = a^2cos(2t)
With polar coordinates, the curve may be plotted in a single quadrant, using reflection and symmetry to produce the remaining plot. In many applications, a higly accurate plot is not desired. Instead, sprites are animated around the curve. In this case, we can use a closed-loop Catmull-Rom spline to approximate the shape. Arc-length parameterization assures uniform velocity during the animation.
The example illustrates how to animate a sequence of sprites around the 'infinity' shape. Study the code and observe how a small sample of points are obtained in the principal quadrant. These points are reflected to generate the remaining control points. The last control point need not be generated as the C-R spline is automatically closed.
Click the 'Animate' button to view the animation. As an experiment, change the parametrization to UINFORM and note the difference in how the sprites move along the shape.
This example requires the Flash™ 9 player.
|