One cell Animate

Description of the function

There is an FAQ which illustrates how to create an animation in which one cell replaces another. Unfortunately this is not always a practical approach, and many users would like a way of creating an animation which only displays a single cell. This function works by creating all of the cells required for an animation and then displaying them in a closed cell group giving the desired effect.

The function

\(createAnimation[
          grList_List]\  := 
\ \ Module[
\ \ \ \ {theCellGroup}, 
\ \ \ \ theCellGroup\  = 
            CellGroupData[
\ \ \ \ \ \ \ \ Append[\((Cell[
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GraphicsData["PostScript", \ 
                          DisplayString[#1]], \ "Graphics", 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ CellTags\  -> \ {"AnimationGroup"}
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ]\  &\ )\)\  /@ \ grList, 
\ \ \ \ \ \ \ \ \ \ Cell[
                  BoxData[
                    ButtonBox[\ "Animate Graphics", 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ButtonFunction\  :> \ 
                        FrontEndExecute[\ {
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NotebookFind[\ ButtonNotebook[], "AnimationGroup", All, \ 
                              CellTags], 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SelectionAnimate[\ 
                              ButtonNotebook[]]}\ ], 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ButtonEvaluator\  -> \ 
                        None, 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Active\  -> \ 
                        True\ ]\ ], 
\ \ \ \ \ \ \ \ \ \ \ \ TextAlignment\  -> \ Center]\ ], \ Closed\ ]; 
\ \ \ \ NotebookWrite[EvaluationNotebook[], \ 
            Cell[theCellGroup]]
\ \ \ \ ]\)

An illustration of using the function.

The easiest way to use the function is to create the animation using the table  function with DisplayFunction -> Identity and then applying the createAnimation function to your animation. You will note createAnimation also creates a button to make it easy to activate the animation. You can also activate the animation in the usual ways, and all of the plots can be revealed by double-clicking on the appropriate cell bracket.

grList  =  
      Table[Plot[Sin[2 Pi f t],  {t,  0,  1}, 
          DisplayFunction  ->  Identity],  {f,  0,  5}]

createAnimation[grList]