# Animation of a sequence of graphic objects: animation

### 7.21.3 Animation of a sequence of graphic objects: animation

The animation command creates animations using sequences of graphic objects, which can be graphs (see Section 7.4) or not (see chapters 13 and 14). The sequence of objects depends most of the time on a parameter and is defined using the seq command but it is not mandatory. To define a sequence of graphic objects with seq, enter the definition of the graphic object (depending on the parameter), the parameter name, its minimum value, its maximum value maximum and optionally a step value.

- animation takes:
  - objs, a sequence of graphic objects.
- animation(objs) draws an animation consisting of the sequence of objects.

#### Examples.

- Input:
  animation(seq(plotfunc(cos(a*x),x),a,0,10))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotfunc(cos(a*x),x),a,0,10,0.5))
  or:
  animation(seq(plotfunc(cos(a*x),x),a=0..10,0.5))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotfunc([cos(a*x),sin(a*x)],x=0..2*pi/a), a,1,10))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotparam([cos(a*t),sin(a*t)], t=0..2*pi),a,1,10))
  Output:
  The output is an animation beginning with:
  FIXME
- Input:
  animation(seq(plotparam([sin(t),sin(a*t)], t,0,2*pi,tstep=0.01),a,1,10))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotpolar(1-a*0.01*t^2, t,0,5*pi,tstep=0.01),a,1,10))
  Output:
  The output is an animation beginning with:
- Input:
  plotfield(sin(x*y),[x,y]); animation(seq(plotode(sin(x*y),[x,y],[0,a]),a,-4,4,0.5))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(display(square(0,1+i*a),filled),a,-5,5))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(line([0,0,0],[1,1,a]),a,-5,5))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotfunc(x^2-y^a,[x,y]),a=1..3))
  Output:
  The output is an animation beginning with:
- Input:
  animation(seq(plotfunc((x+i*y)^a,[x,y], display=filled),a=1..10)
  Output:
  The output is an animation beginning with:

Remark: You can also define the sequence with a program. For example if you want to draw the segments of length 1,√2…√20 constructed with a right triangle of side 1 and the previous segment (note that there is a c:=evalf(..) statement to force approximate evaluation otherwise the computing time would be too long):
Input:

`seg(n):={`
`local a,b,c,j,aa,bb,L;`
`a:=1;`
`b:=1;`
`L:=[point(1)];`
`for(j:=1;j<=n;j++){`
`L:=append(L,point(a+i*b));`
`c:=evalf(sqrt(a^2+b^2));`
`aa:=a;`
`bb:=b;`
`a:=aa-bb/c;`
`b:=bb+aa/c;`
`}`
`L;`
`}:;`

then:

L:=seg(20); s:=segment(0,L[k])$(k=0..20)

Output:

then:

animation(s)

The output is an animation displaying the segments one at a time, beginning with: