6.33 animate: vertical lines and multiple colors (14.3.00)

6.33.1 Nathan Sokalski

I have been playing with the animate command, and have recently encountered a situation in which I need a vertical line (it will move from side to side, but remain vertical). Because there is no function of x that can give me this, I am forced to use a command. I have found the command line([a,b],[a,b]), which is used to draw a line segment, in the package plottools, but this did not appear to work with animations. How do I make a vertical line in an animation?

Most of my animations also contain more than 1 function. I do know about the option color=, but unlike the plot command, animate will only let you put one color there. I find it hard to believe that you must make everything the same color. Is there a way to use multiple colors like you do with the plot command?

Note: I use Maple V Release 5 Student Version

6.33.2 John Little (15.3.00)

About your questions concerning animations. 1) You want to plot your vertical lines as parametric curves. 2) You can generate several animations with the curves plotted in different colors, then show them together using the display command from the plots package. Here’s a simple example showing both things:


6.33.3 Carl DeVore (15.3.00)

Using the "display" command with the argument "insequence= true" is a much more flexible way to produce animations. The "animate" command only works with functions. Any plot whatsoever can be animated with the "insequence" option, including plots containing text.

The vertical line x=a can be expressed as a function in polar coordinates as r = a*sec(theta). You can then use the range of theta to control the height of the line segment. You can include the argument "coords= polar" to the animate command.

There are many other ways to draw a line segment. You could use a parametric plot:

   plot([a, t,  t= c..d])

will plot a vertical line segment from [a,c] to [a,d]. But this is using an elephant gun to swat a fly.

Other ways to draw the line segment from [a,b] to [c,d]:

   plot( [[a,b],[c,d]] ) 
   pointplot ( [[a,b],[c,d]], connect= true)

and my favorite (because it will avoid some function call overhead if you are putting many line segments in one display):


Note the capital letters.

Putting it all together, the following command will produce an animation of n+1 vertical line segments moving through the color spectrum:

   display([seq(CURVES( [[k/n,0],[k/n,1]], COLOR(HUE,k/n)), k= 0..n)] 
          ,thickness= 9, view= [0..1,0..1], insequence= true)

Using n=100, this command executes in 0.41 seconds on my SPARCstation 4, not a particularly fast computer; whereas doing the equivalent thing with the plot command takes over 5 secs; with line, 0.7 secs; and with pointplot, 1.27 secs.

There are many good examples of using the "insequence" option in _Calculus the Maple Way_ by Robert B Israel. In particular, note that each frame of the animation can itself be a complex structure created with the display command.

If anyone wants them, I will email them worksheets with animations of:

1. the osculating circle rolling along a 2D or 3D curve

2. Newton’s method for functions of a single real variable. This one uses text in the animation to print

a. the equation of the tangent line at each iteration

b. the x-intercept at each iteration

c. context-sensitive advice on how improve the approximation.

6.33.4 Preben Alsholm (16.3.00)

To get a vertical line x=a, you could use a parametric representation, e.g. [a, t, t=0..1].

Try the following:

 f:= t -> 1-t^2: 

6.33.5 Norbert Roth (16.3.00)

Here’s a little ’dirty’ procedure which does the trick.

           local i,j; 

Short description:

The procedure pl produces a plot structure. 
The parameters are: xa,ya   - (coordinates of the beginning point of the line) 
                    xe,xe   - (coordinates of the ending point of the line) 
                    xstep   - difference between the x coordinates 
                              of the actual point and next point to be drawn 
                    ystep   - difference between the y coordinates 
                              of the actual point and next point to be drawn 
                    xytimes - how many animation frames 
> gp:=pl(-.25,-1.5,.25,-1,Pi/6,5/12,6): 
> display({gp},view=[-.25..3.55,-3..3]);

Displaying several animation in one window:

E.g. create normal animation via:

> fp:=animate(sin(x)*t*cos(x),x=0..Pi,t=1..5,frames=6,color=blue): 
> display({gp,fp},color=green); 
| your color question

Look at the above examples how to manage it, should be obvious.

Add. Info: The outer color definition used in ’display’ is overwritten temporary in ’fp’.

Further and more detailed info in the manuals and help pages, e.g. ?plot[structure], ?plot[options], ...

6.33.6 Stanley J Houghton (16.3.00)

I use the plot command with a list of coordinates (two in this example). Try as an example:


It plots a unit verticle line at various x positions.

6.33.7 Symancyk, Daniel (16.3.00)

You can use display of the plots package with insequence=true. Create a plot structure for each frame and specify the color you want in each frame.

The following will produce an animation with four frames. In the first frame we have the line x=1 in blue. In the second one x=1.5 is green, etc.


In the work above all of the vertical lines have the same height. If you want to vary the height using a function and you’d like the function to be displayed as well, then the following will do it.

h will give the height over interval [a,b]

> h:=x->x^2+1; 
> a:=-1;b:=2;

there will be 26 frames

> n:=25;

the color of each vertical line is randomly determined

      a..b,color=COLOR(RGB,rand()/10^12, rand()/10^12, rand()/10^12)): 
 for j from 0 to 25 do 
 p[ j ]:=plots[display]({g(h,a,b, j),c}): 
 s0:=seq(p[ j ], j=0..25): 

6.33.8 Douglas B. Meade (16.3.00)

If I understand your request, it is possible to create what you want using the display command from the plots package. The following sequence of commands illustrates the general idea by drawing the vertical height of a function at 21 uniformly spaced points in the interval [-1,1].

> restart; 
> with( plots ): 
> f := x -> x^2+1; 
                           f := x -> x  + 1 
> P := plot( f, -1..1, color=BLUE ): 
> P2 := seq( 
         display( P, 
                  plot( [[x,0],[x,f(x)]] ) ), 
         x=[i/10 $ i=-10..10] ): 
> display( P2, insequence=true );

I hope you can modify this for your needs,