Dynamic Tools for Creating Videos and Illustrations

Dave Withoff, Wolfram Research

Join the Conversation #WolframTechConf

ABSTRACT

This short talk covers simple dynamic programming (using Manipulate, Dynamic, etc.) methods for creating static and animated illustrations, and for controlling illustrations in videos and presentations. This talk will also include an overview of how those methods fit within a broader strategy for creating notebook-based presentations.

Using Manipulate to Create Illustrations

Consider the task of positioning a label on a parameterized plot where it is convenient for the label to be repositioned for different values of a parameter:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->Text[Style["inflection point",16],{-1,2}]],{{p,0},-4,4}]

Rather than positioning the label by trial and error, it can be more convenient to use Manipulate:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->Text[Style["inflection point",16],{tx,ty}]],{{p,0},-4,4},{tx,-1.5,0},{ty,0,4}]

Add an arrow:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->{Text[Style["inflection point",16],{-0.8,2.2}],Arrow[{{tx,ty},{0,p}}]}],{{p,0},-4,4},{tx,-1.5,0,Appearance->"Labeled"},{ty,0,4,Appearance->"Labeled"}]

Add a second label and a second arrow to be used for p>2, and position the text:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->If[p<2,{Text[Style["inflection point",16],{-0.8,2.2}],Arrow[{{-0.8,1.8},{0,p}}]},{Text[Style["inflection point",16],{tx,ty}],Arrow[{{tx,ty},{0,p}}]}]],{{p,0},-4,4},{tx,-1.5,1.5,Appearance->"Labeled"},{ty,-4,4,Appearance->"Labeled"}]

Position the arrow:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->If[p<2,{Text[Style["inflection point",16],{-0.8,2.2}],Arrow[{{-0.8,1.8},{0,p}}]},{Text[Style["inflection point",16],{0.8,1.2}],Arrow[{{tx,ty},{0,p}}]}]],{{p,0},-4,4},{tx,-1.5,1.5,Appearance->"Labeled"},{ty,-4,4,Appearance->"Labeled"}]

Result:

Manipulate[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5},Epilog->If[p<2,{Text[Style["inflection point",16],{-0.8,2.2}],Arrow[{{-0.8,1.8},{0,p}}]},{Text[Style["inflection point",16],{0.8,1.2}],Arrow[{{0.26,1.3},{0,p}}]}]],{{p,0},-4,4},{tx,-1.5,1.5,Appearance->"Labeled"},{ty,-4,4,Appearance->"Labeled"}]

Off-Screen Controls Using Dynamic

Now consider moving the controls for that demonstration into a separate notebook.

One way to set up off-screen controls is to set up controls in a control notebook and put a Dynamic output in the presentation notebook.

For example, this slider controls the subsequent dynamic output:

p=0;Slider[Dynamic[p],{-4,4}]

Dynamic[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5}]]

To get off-screen controls, just put the slider in the control notebook and the Dynamic output in the presentation notebook.

Off-Screen Controls Using Manipulate

If you don't want to program your own sliders you can also use Manipulate with LocalizeVariables->False:

Manipulate[p,{{p,0},-4,4},LocalizeVariables->False]

Dynamic[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5}]]

As before, to get the display in a separate notebook, just copy and paste the output of Dynamic into that separate notebook.

Alternatively, you could use a Manipulate that assigns a value to a global variable:

Manipulate[globalVariable=Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5}],{{p,0},-4,4}]

Dynamic[globalVariable]

Off-Screen Conrols Using NotebookWrite

If it is inconvenient to copy and paste something into the display notebook, or if you just want to have all of your programming contained in the display notebook, you can use NotebookWrite to put content into the display notebook.

If the dispay notebook hasn't already been created, you can create it using CreateNotebook, and move the insertion point to the end of the notebook:

displayNotebook=CreateDocument[Cell["Inflection Points", "Title"],WindowTitle->"Dave's Presentation",WindowSize->{800,500},WindowMargins->{{0, Automatic},{Automatic,0}}]

SelectionMove[displayNotebook,After,Notebook]

One approach is to directly write the entire output of the plot into a cell in the display notebook:

nbWrite[c_]:=NotebookWrite[displayNotebook,Cell[BoxData[ToBoxes[c]],"Output"],All]

Manipulate[nbWrite[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5}]];p,{{p,0},-4,4}]

Another approach is to write the output of a suitable Dynamic into the display notebook and set up separate controls in the control notebook:

p=0;nbWrite[Dynamic[Plot[p+Tan[x],{x,-π/2,π/2},PlotRange->{-5,5}]]]

Slider[Dynamic[p],{-4,4}]