Function Repository Resource:

SimpleListAnimate

Source Notebook

Create an animation from a list of expressions

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["SimpleListAnimate"][{expr1,expr2,}]

generates an animation whose frames are the successive expri.

ResourceFunction["SimpleListAnimate"][list,fps]

displays fps frames per second.

Details and Options

ResourceFunction["SimpleListAnimate"] is similar to ListAnimate, but does not display any controls.
To start/stop the animation, click on the image.
The expri can be any expressions, and do not need to be graphics.
ResourceFunction["SimpleListAnimate"] generates an Interpretation object that’s interpreted as list.
If it is not specified, fps will by default be chosen so that the animation lasts a total of 5 seconds.
ResourceFunction["SimpleListAnimate"] has the same options as Manipulate, with the following additions and changes:
AlignmentAutomatichow to align objects in the display area
AnimationDirectionForwardthe direction of the animation
AnimationRepetitionsInfinityhow many times to run before stopping
AnimationRunTime0time elapsed since the animation last started running, or 0 if the animation is not running
AnimationTimeIndexAutomatictime index for the animation, where 0 is the beginning and the value of DefaultDuration is the end
DefaultDuration5the default duration in seconds
DisplayAllStepsTruewhether to force all expri to be displayed
ImageSizeAllthe overall image size to use
ResourceFunction["SimpleListAnimate"] by default displays in an area large enough to fit any of the expri.
With the option setting ImageSizeAutomatic, ResourceFunction["SimpleListAnimate"] leaves space only for the expri currently being displayed.

Examples

Basic Examples (2) 

Animate a sequence of images:

In[1]:=
ResourceFunction["SimpleListAnimate"][
 Table[Plot[Sin[n x], {x, 0, 10}], {n, 5}]]
Out[1]=

Create an animated bird:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/53c1c4f3-29e8-4ffc-9f76-e90dcfea1871"]
Out[2]=

Use the resource function BirdSay with the bird:

In[3]:=
ResourceFunction["BirdSay"][Row[{bird, Style["?", 30]}]]
Out[3]=

Scope (4) 

SimpleListAnimate Content (2) 

Animate a list of Wolfram Language expressions:

In[4]:=
ResourceFunction[
 "SimpleListAnimate"][{Style["\[MathematicaIcon]", Large], "string", Framed[x + y], Graphics[Rectangle[], ImageSize -> 20]}]
Out[4]=

Animate a sequence of expressions:

In[5]:=
ResourceFunction["SimpleListAnimate"][Table[Factor[x^n - 1], {n, 50}]]
Out[5]=

Force the expressions to wrap at a fixed width:

In[6]:=
ResourceFunction["SimpleListAnimate"][
 Table[Pane[Factor[x^n - 1], 200], {n, 50}]]
Out[6]=

SimpleListAnimate Control (2) 

By default, the animation lasts a total of five seconds:

In[7]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Disk[{0, 0}, n], PlotRange -> 5], {n, 5}]]
Out[7]=

Control the display rate of each frame using a second argument:

In[8]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Disk[{0, 0}, n], PlotRange -> 5], {n, 5}], 1]
Out[8]=

Options (10) 

Alignment (1) 

Use preset values:

In[9]:=
Table[ResourceFunction["SimpleListAnimate"][{"a", "hello world", "b"},
   Alignment -> a, AnimationRunning -> False], {a, {Left, Center, Right}}]
Out[9]=

AnimationDirection (1) 

Control the direction of animation:

In[10]:=
Table[ResourceFunction["SimpleListAnimate"][{1, 2, 3}, AnimationDirection -> a, AnimationRunning -> False], {a, {Forward, Backward, ForwardBackward}}]
Out[10]=

AnimationRate (1) 

Control the animation rate:

In[11]:=
Table[ResourceFunction["SimpleListAnimate"][Range[10], AnimationRate -> a, AnimationRunning -> False], {a, {0.5, 1}}]
Out[11]=

AnimationRepetitions (1) 

Control the number of animation cycles:

In[12]:=
Table[ResourceFunction["SimpleListAnimate"][{1, 2, 3}, AnimationRepetitions -> a, AnimationRunning -> False], {a, 1, 2}]
Out[12]=

AnimationRunning (2) 

By default, SimpleListAnimate starts running when evaluated:

In[13]:=
ResourceFunction["SimpleListAnimate"][{1, 2, 3}]
Out[13]=

By setting AnimationRunningFalse, SimpleListAnimate starts in a paused state:

In[14]:=
ResourceFunction["SimpleListAnimate"][{1, 2, 3}, AnimationRunning -> False]
Out[14]=

DefaultDuration (1) 

Control the time duration of one animation cycle:

In[15]:=
Table[ResourceFunction["SimpleListAnimate"][{1, 2, 3}, DefaultDuration -> a, AnimationRunning -> False], {a, 1, 2}]
Out[15]=

ImageSize (3) 

By default, SimpleListAnimate leaves enough space for its content without ever having to resize:

In[16]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Circle[], ImageSize -> s], {s, 20, 50, 10}], AnimationRunning -> False]
Out[16]=

By setting ImageSize, leave just enough space for the current display:

In[17]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Circle[], ImageSize -> s], {s, 20, 50, 10}], ImageSize -> Automatic, AnimationRunning -> False]
Out[17]=

A fully custom image size:

In[18]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Circle[], ImageSize -> s], {s, 20, 50, 10}], ImageSize -> {300, 100}, AnimationRunning -> False]
Out[18]=

Applications (4) 

Collect the individual steps in an optimization problem:

In[19]:=
{sol, {steps}} = Reap[FindMinimum[(x - 1)^2 + 100 (y - x^2)^2, {{x, -1}, {y, 1}}, StepMonitor :> Sow[{x, y}]]]
Out[19]=

Animate the progression of the solver:

In[20]:=
ResourceFunction["SimpleListAnimate"][
 Table[ListLinePlot[Take[steps, i], Mesh -> All, PlotRange -> {{-1, 1.1}, {-1, 1.1}}], {i, Length[steps]}]]
Out[20]=

Collect individual steps when solving the sine-Gordon PDE:

In[21]:=
{sol, {steps}} = Reap@NDSolve[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t, t\)]\(u[t, x]\)\) == \!\(
\*SubscriptBox[\(\[PartialD]\), \(x, x\)]\(u[t, x]\)\) + Sin[u[t, x]] , u[0, x] == E^-x^2, 
\!\(\*SuperscriptBox[\(u\), 
TagBox[
RowBox[{"(", 
RowBox[{"1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 8}, {x, -10, 10}, StepMonitor :> Sow[Plot[u[t, x], {x, -10, 10}, PlotRange -> {0, 8}]]]; // Quiet

Animate the solution progress:

In[22]:=
ResourceFunction["SimpleListAnimate"][steps]
Out[22]=

An implementation of LU decomposition that uses Sow on all intermediate steps:

In[23]:=
LU[A_] :=
  Module[{m, n, L, U}, {m, n} = Dimensions[A];
   L = IdentityMatrix[n]; Sow[L, "L" ];
   U = A; Sow[U, "U"];
   Do[
    L[[k ;; n, k]] = U[[k ;; n, k]]/U[[k, k]]; Sow[L, "L"];
    U[[(k + 1) ;; n, k ;; n]] = U[[(k + 1) ;; n, k ;; n]] - L[[(k + 1) ;; n, {k}]] . U[[{k}, k ;; n]]; Sow[U, "U"];
    , {k, 1, n - 1}];
   {L, U}
   ];

Reap the intermediate results and make an animation:

In[24]:=
LUAnimate[A_, f_] :=
 Module[ {lu, l, u}, {lu, {{l}, {u}}} = Reap[ LU[ A ], {"L", "U"}];
  ResourceFunction["SimpleListAnimate"][
   Table[Row[{f[l[[i]]], ".", f[u[[i]]], "==", f[A]}], {i, Length[l]}]]
  ]
In[25]:=
LUAnimate[RandomInteger[10, {5, 5}], MatrixForm]
Out[25]=

Use MatrixPlot for larger matrices:

In[26]:=
LUAnimate[RandomInteger[10, {20, 20}], MatrixPlot[#, FrameTicks -> None, ImageSize -> 100] &]
Out[26]=

Show changing moon phases in a month:

In[27]:=
dates = DateRange[DateObject[{2014, 1, 1, 12}], DateObject[{2014, 1, 31, 12}], 1];
In[28]:=
mp = Values[MoonPhase[dates, "Icon"]];
sf = Values[MoonPhase[dates, "Fraction"]];
In[29]:=
list = MapThread[
   Framed[Labeled[ImageResize[#1, 45], Style[#3, Bold, FontFamily -> "Helvetica"]], Background -> Lighter[ColorData["StarryNightColors", #2], .3]] &, {mp, sf, Range[Length[mp]]}];
In[30]:=
ResourceFunction["SimpleListAnimate"][list]
Out[30]=

Properties & Relations (3) 

Use SimpleListAnimate to animate output from Table:

In[31]:=
ResourceFunction["SimpleListAnimate"][
 Table[Plot[BesselJ[n, x], {x, 0, 10}, PlotRange -> {{0, 10}, {-.75, .75}}], {n, 1, 5, .25}], AnimationRunning -> False]
Out[31]=

Use Animate for animations that depend on a parameter:

In[32]:=
Animate[Plot[BesselJ[n, x], {x, 0, 10}, PlotRange -> 0.7], {n, 1, 5, 1}, AnimationRunning -> False]
Out[32]=

Use Animator when assembling a custom animation frame:

In[33]:=
Column[{Animator[Dynamic[t], {0, 1}], Dynamic@Plot[Sinc[t x], {x, 0, 10}, PlotRange -> 1]}]
Out[33]=

Neat Examples (1) 

Animate a sequence of disks with random sizes:

In[34]:=
ResourceFunction["SimpleListAnimate"][
 Table[Graphics[Disk[], ImageSize -> RandomReal[100]], {50}]]
Out[34]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 03 May 2019

Related Resources

License Information