This page contains large animations.
Back to the Maple Tutorial Table of Contents
In Maple, there are two ways to do animations. You can use the plots[animate]() command, or you can use sequences. Using the plots[animate]() command is the easier of the two, but you can only use plots[animate]() if your function itself is changing. You can use sequences to change any aspect of the plot.
Example: You could use plots[animate]() to draw xt, t=1..10, but you couldn't use plots[animate]() to draw x2 with an increasing x-axis.
Using plots[animate]() is a lot like the plot() statement. There is one difference: you need to include another variable which changes for each frame in the animation. This variable must come after the dependent variable (in this case, x)
> with(plots):
> animate(x*t,x=-10..10,t=1..10,view=-10..10);
![[Maple Plot]](../images/animate-011.gif)
When you generate the animation, Maple displays the first frame. To play the animation, click the animation, and click the Play button on the context bar. You can also use the other buttons on the context bar to rewind the animation, make it play continuously, and to step through the animation frame-by-frame.
You can name your "animation variable" something else.
> animate(x*theta,x=-10..10,theta=1..10,view=-10..10);
![[Maple Plot]](../images/animate-012.gif)
In the last two statements, I have used the view plot option. In some plotting commands, Maple requires that you use the view=a..b format instead of a..b to control the y-axis. You can use other plot options with plots[animate]().
> animate(sin(x*t),x=-2*Pi..2*Pi,t=0..4,color=red);
![[Maple Plot]](../images/animate-013.gif)
You can also specify how many frames the animation should take. (The number of frames must be an integer)
> animate(x/t,x=-10..10,t=1..50,frames=500);
The default number of frames is 16.
Using sequences to do animations requires knowledge of the seq() command. The seq() command lets you generate a sequence of items dependent on two bounds.
Example:
> seq(x^t,t=1..5);
![]()
seq() and $ are different because seq() lets you create a sequence of unique values. $ lets you create a sequence of the same value.
With the power of seq(), we can start to build an animation.
Example: Build an animation in which the function increases its exponent from 1 to 5 and the x-axis increases from -1..1 to -5..5.
First, lets create the basic plot() statement we will use.
> plot(x^t,x=-t..t);
Error, (in plot) parameter range must evaluate to a numeric
We get an error message because t isn't defined. Let's wrap the plot() statement in a seq() statement to define t.
> seq(plot(x^t,x=-t..t),t=1..5):
I used the colon here so we wouldn't get pages of PLOT structures. Now, let's display the plot structures. (Remember, the plots package is already loaded.)
> display(seq(plot(x^t,x=-t..t),t=1..5));
![[Maple Plot]](../images/animate-016.gif)
What a lovely, static picture! We need to tell plots[display]() to display the sequence of plots as an animation. I also included the y-axis limits to make the graph look better. Since I wanted the y-axis to grow with the x-axis, i used -t..t.
> display(seq(plot(x^t,x=-t..t,-t..t),t=1..5),insequence=true);
![[Maple Plot]](../images/animate-017.gif)
As you can see, the animation goes too fast. To make the animation appear slower, we will give it more frames by including more plot statements. As you may recall, x$n gives you n x's in a sequence. We can use that principle to include 10 plot() statements in each frame. Therefore, the display statement displays 10 frames for each t. (This works because the $ operator is executed first. The seq() statement then contains 10 plot statements in a sequence. Replacing all t's with the current value of t will allow the plot() statements to evaluate to a PLOT structure.)
> display(seq(plot(x^t,x=-t..t,-t..t)$10,t=1..5),insequence=true);
![[Maple Plot]](../images/animate-018.gif)