plots - Maple Programming Help

Home : Support : Online Help : Graphics : Packages : plots : plots/animate

plots

 animate
 create a 2-D or 3-D animation on one parameter

 Calling Sequence animate(plotcommand, plotargs, t=a..b, options) animate(plotcommand, plotargs, t=L, options)

Parameters

 plotcommand - Maple procedure that generates a 2-D or 3-D plot plotargs - list of arguments to the plot command t - name of parameter on which the animation is made a, b - real constants giving the range of the animation L - list of values options - (optional) equation(s) of the form option=value; specify options for the animate command or the plot command

Description

 • The animate command can be used to generate an animation on one parameter for any Maple plot command, both 2-D and 3-D.  For example, the following generates an animation of the sine curve $A\mathrm{sin}\left(x\right)$ on the amplitude $A$.
 > plots[animate]( plot, [A*sin(x), x=0..10], A=0..2 );
 This command creates an animation with 25 frames.
 To run the animation using the worksheet interface:
 1 Click the plot. The plot toolbar is displayed.
 2 In the toolbar, click the Play button.
 Alternatively, right-click (Control-click, on Macintosh) the plot to display the context menu.  Select Animation > Play.
 • In the first calling sequence, an animation with 25 frames is created for 25 equally spaced real values of the animation parameter A on the range a..b. In the second calling sequence, the given list of values is used for frames of the animation.
 • The first input, plotcommand is the Maple plotting command. It must return a Maple 2-D or 3-D plot. The second input, plotargs, is a list of arguments for plotcommand. To plot the sine function for two different frequencies, you can use:
 > plot( sin(2*x), x=-Pi..Pi, thickness=2 );
 > plot( sin(3*x), x=-Pi..Pi, thickness=2 );
 • To convert this to an animation on the amplitude, put the above arguments to the plot command in a list as follows.
 > plots[animate]( plot, [sin(A*x), x=-Pi..Pi, thickness=2], A=1..5 );
 • To animate a curve being traced out in time, make the domain parameter(s), $x$ in the above example, depend on the animation parameter.  For example, here is a sine curve being traced out in time $t$.
 > plots[animate]( plot, [sin(t), t=0..x], x=0..4*Pi );
 • Animations in 3-D are similarly obtained.  For example:
 > plots[animate]( plot3d, [sin(A)*(x^2+y^2), x=-2..2, y=-2..2], A=0..2*Pi );
 • The remaining arguments to the animate command are interpreted as options.  They are equations of the form option = value. The options described below are specific to the animate command. Other options, such as scaling=constrained, are passed on the to plots[display] command.
 • By default, the animate command generates 25 frames equally spaced on the animation parameter interval A=a..b.  The optional argument frames=n specifies that the animation is to have $n$ frames.
 Note: $n$ must be a non-negative integer.
 • By default, the numerical value of the animation parameter A is displayed to 5 significant digits for each frame in the animation in the title region of the plot.  The optional argument paraminfo=false turns this information off.  The optional argument digits=n can be used to display a different number of significant digits.
 Note: $n$ must be a positive integer.
 • The background=p option accepts a color or image as the background of the animation, as described in the plot/options help page. With the animate command, additional values for $p$ are allowed. The value of $p$ can be a PLOT or PLOT3D object (the output of a 2-D or 3-D plotting command) or a list of such objects. In the latter case, the plots[display] command will be called to combine the plot structures into a single background plot. The value of $p$ can also be a numerical value, in which case the plot generated by plotcommand for A=p is used for the background.
 • The trace=n option specifies that a trace of frames specified by $n$ be displayed, where $n$ is a positive integer or a list of positive integers. When $n$ is an integer, then $n$ frames, equally-spaced in the animation range, will be display in all frames after their initial display. Thus, the final frame of the animation displays $n+1$ frames. For example, if the number of frames is 25 and $n=5$, then frames 1, 6, 11, 15, and 20 display in subsequent frames.  When $n$ is a list of integers, then the frames in those positions are the ones included in the trace. Each integer in $n$ must be no larger than the maximum number of frames. The default is $n=0$, that is, no trace is shown.
 • If each frame in the animation must contain two or more different plots, write a Maple procedure that creates each frame and animate that procedure.  See the last example in the Examples section below.
 • To construct an animation sequence from existing plots, use the plots[display] function with the insequence option. This is what the animate command does.
 • For information on viewing animations, see Overview of Animation Menu.
 Note: You can save animations as an animated GIF file. For more information on producing GIF files, see plot/device.

Examples

To play an animation in this help page, right-click (Control-click, on Macintosh) the plot to display the context menu.  Select Animation > Play.

The first few examples are for animating a curve or surface on a parameter.

 > $\mathrm{with}\left(\mathrm{plots}\right):$
 > $\mathrm{animate}\left(\mathrm{plot},\left[A{x}^{2},x=-4..4\right],A=-3..3\right)$
 > $\mathrm{animate}\left(\mathrm{plot},\left[A{x}^{2},x=-4..4\right],A=-3..3,\mathrm{trace}=5,\mathrm{frames}=50\right)$
 > $\mathrm{animate}\left(\mathrm{plot},\left[A{x}^{2},x=-4..4\right],A=-3..3,\mathrm{trace}=\left[30,35,40,45,50\right],\mathrm{frames}=50\right)$

The next example shows how to do this in 3 dimensions.

 > $\mathrm{animate}\left(\mathrm{plot3d},\left[A\left({x}^{2}+{y}^{2}\right),x=-3..3,y=-3..3\right],A=-2..2,\mathrm{style}=\mathrm{patchcontour}\right)$

The next examples are of a circle and a hyperbola given implicitly as an equation. See the plots[implicitplot3d] command to generalize these to 3 dimensions.

 > $\mathrm{animate}\left(\mathrm{implicitplot},\left[{x}^{2}+{y}^{2}={r}^{2},x=-3..3,y=-3..3\right],r=1..3,\mathrm{scaling}=\mathrm{constrained}\right)$
 > $\mathrm{animate}\left(\mathrm{implicitplot},\left[{x}^{2}+Axy-{y}^{2}=1,x=-2..2,y=-3..3\right],A=-2..2,\mathrm{scaling}=\mathrm{constrained}\right)$

The next few examples are for animating a curve in 2 or 3 dimensions in time. Here is a sine wave and a damped sine wave animated in time.

 > $\mathrm{animate}\left(\mathrm{plot},\left[\left[\mathrm{sin}\left(t\right),\mathrm{sin}\left(t\right){ⅇ}^{-\frac{t}{5}}\right],t=0..x\right],x=0..6\mathrm{π},\mathrm{frames}=50\right)$

The following is a circle traced out using its trigonometric parametrization and its rational parametrization.  The latter does not result in a uniform motion.

 > $\mathrm{animate}\left(\mathrm{plot},\left[\left[\mathrm{cos}\left(t\right),\mathrm{sin}\left(t\right),t=0..A\right]\right],A=0..2\mathrm{π},\mathrm{scaling}=\mathrm{constrained},\mathrm{frames}=50\right)$
 > $\mathrm{animate}\left(\mathrm{plot},\left[\left[\frac{1-{t}^{2}}{1+{t}^{2}},\frac{2t}{1+{t}^{2}},t=-10..A\right]\right],A=-10..10,\mathrm{scaling}=\mathrm{constrained},\mathrm{frames}=50,\mathrm{background}="LightGrey",\mathrm{view}=\left[-1..1,-1..1\right]\right)$

Here is a curve in 3-D space defined parametrically.

 > $\mathrm{opts}≔\mathrm{thickness}=5,\mathrm{numpoints}=100,\mathrm{color}=\mathrm{black}:$
 > $\mathrm{animate}\left(\mathrm{spacecurve},\left[\left[\mathrm{cos}\left(t\right),\mathrm{sin}\left(t\right),\left(2+\mathrm{sin}\left(A\right)\right)t\right],t=0..20,\mathrm{opts}\right],A=0..2\mathrm{π}\right)$

The following example has a surface as the background and a curve traced on the surface.  The background frame is a 3-D plot of the surface.  The curve is a heavy black line.

 > $B≔\mathrm{plot3d}\left(1-{x}^{2}-{y}^{2},x=-1..1,y=-1..1,\mathrm{style}=\mathrm{patchcontour}\right):$
 > $\mathrm{opts}≔\mathrm{thickness}=5,\mathrm{color}=\mathrm{black}:$
 > $\mathrm{animate}\left(\mathrm{spacecurve},\left[\left[t,t,1-2{t}^{2}\right],t=-1..A,\mathrm{opts}\right],A=-1..1,\mathrm{frames}=11,\mathrm{background}=B\right)$

The remaining examples show animations of objects in time. The first is an illustration of simple harmonic motion. We show a blue ball moving up and down in 2 dimensions. In the example, each frame is defined by a Maple procedure ball.

 > ball := proc(x,y) plots[pointplot]([[x,y]],color=blue,symbol=solidcircle,symbolsize=40) end proc:
 > $\mathrm{animate}\left(\mathrm{ball},\left[0,\mathrm{sin}\left(t\right)\right],t=0..4\mathrm{π},\mathrm{scaling}=\mathrm{constrained},\mathrm{frames}=100\right)$

To roll the ball along the sine wave, make the sine wave the background frame and animate a ball along it, or leave a trace of the ball.

 > $\mathrm{sinewave}≔\mathrm{plot}\left(\mathrm{sin}\left(x\right),x=0..4\mathrm{π}\right):$
 > $\mathrm{animate}\left(\mathrm{ball},\left[t,\mathrm{sin}\left(t\right)\right],t=0..4\mathrm{π},\mathrm{frames}=50,\mathrm{background}=\mathrm{sinewave},\mathrm{scaling}=\mathrm{constrained}\right)$
 > $\mathrm{animate}\left(\mathrm{ball},\left[t,\mathrm{sin}\left(t\right)\right],t=0..4\mathrm{π},\mathrm{frames}=50,\mathrm{trace}=10,\mathrm{scaling}=\mathrm{constrained}\right)$

This final example contains several objects in the animation.

 > F := proc(t)      plots[display]( plottools[line]([-2,0], [cos(t)-2, sin(t)], color=blue), plottools[line]([cos(t)-2, sin(t)], [t, sin(t)], color=blue), plot(sin(x), x=0..t, view=[-3..7, -5..5])      ); end proc:
 > $\mathrm{animate}\left(F,\left[\mathrm{θ}\right],\mathrm{θ}=0..2\mathrm{π},\mathrm{background}=\mathrm{plot}\left(\left[\mathrm{cos}\left(t\right)-2,\mathrm{sin}\left(t\right),t=0..2\mathrm{π}\right]\right),\mathrm{scaling}=\mathrm{constrained},\mathrm{axes}=\mathrm{none}\right)$