Animation: part 2
Lists
Another tool for animations is that of lists. A list is an ordered sequence of expressions enclosed in square brackets. Appending an element x to a list L is done by [op(L),x]. For example, here is a list of numbers:
> primes := [2, 3, 5, 7];
> primes := [op(primes), 11];
> primes := [op(primes), 13];
Lists may be more complex. They may be a sequence of expressions, plot objects, or even animations. For example:
> restart:
> with(plots):
> a := plot(x, x=0..1, color=BLUE):
> b := plot(x^2, x=0..1, color=RED):
> c := plot(x^3, x=0..1, color=GREEN):
> L := [a,b,c]:
> display(L);
> display(L, insequence=true);
Notice the significance of insequence = true. Here is a more dramatic example:
> plotList := []; #
This sets the initial list L empty.
> for i from 1 to 50 do
plotList := [op(plotList), plot(x^i, x=0..1, color = BLUE)]
end do :
> display(plotList, insequence = false);
> display(plotList, insequence = true);
Again, notice the significance of the insequence option.
In the next example, we define a list that consists of a sequence of animations, each "animation" being a static representation of a graph. The reason that we define each element of the list as an animation is that we can control the time lag required to go from one list item to the next.
> restart:
> with(plots):
> a:= animate(x, x=0..1, t=0..1,
color=BLUE):
> b:= animate(x^2, x=0..1, t=0..1, color=RED):
> c:= animate(x^3, x=0..1, t=0..1, color=GREEN):
> animationList :=[a,b,c]:
> display(animationList, insequence=false);
> display(animationList, insequence=true);
What happens when insequence is false?
Experiment with the number of frames for each animation. Increasing
the number of frames will increase the time lag; decreasing the number
of frames (from the default of 16) will decrease the time lag.
The next example utilizes a graphics object in the plottools library:
> restart:
> with(plots):
> with(plottools);
> square := rectangle ([-1/2, -1/2], [1/2,1/2],
color = BLUE); # Here we specify the lower-left and upper-right
corners of our rectangle.
> display(square, axes=NONE);
> square2 := rotate(square, Pi/3);
# The rotate command rotates the square in the counterclockwise direction.
The angle of rotation (in radians) is given by the second argument of rotate.
> display(square2);
> sqList := []; # we initialize
our list to empty.
> for i from 0 to 25 do
sqList:= [op(sqList), rotate(square, (i/25)*2*Pi)]
end do:
> display(sqList);
> display(sqList, insequence=true);
The Cycloid
The equation of the famous cycloid is given by: x = q
-
sin q,
y = 1 - cos q.
The following example illustrates an animation of the cycloid:
> animate({[u+cos(theta), 1+sin(theta), theta=0..8*Pi ], [theta*u-sin(theta*u),1-cos(theta*u), theta=0..1]}, u=0..8*Pi, frames=50, view=[0..8*Pi, 0..8*Pi] );
Explain the meaning of each of the two curves
in the above animation.
rotating globe from Animation
City