Customizing Manipulate's Autorun

• To: mathgroup at smc.vnet.net
• Subject: [mg110625] Customizing Manipulate's Autorun
• From: "Ingolf Dahl" <ingolf.dahl at telia.com>
• Date: Tue, 29 Jun 2010 06:58:55 -0400 (EDT)

```I was about to write to MathGroup with a question how to customize the
Autorun feature of Manipulate to stop it from running the controls
sequentially and instead shake them simultaneously. But when I was preparing
the question I found a solution, and since it was nontrivial I want to share
it. The trick was to create a special hidden control, which manipulates the
default values of the other controls dynamically.

It is in the essence of this kind of solutions that it describes
undocumented, or poorly documented features of Mathematica, and such
features might be changed in future versions. But if the content of this
notebook already was described in the documentation, there was no reason for
me to repeat it.

Sometimes we might want to control the Autorun feature of a Manipulate cell.
Autorun can be started from the little "+" in a gray circle in the upper
right corner of the Manipulate cell. Let us start with a simple Manipulate
cell.

Manipulate[
Graphics[{color, Disk[{x, y}, 0.1]},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}], {{color,
Black}, {Black -> "Black", Red -> "Red"}}, {{x, 0}, -1,
1}, {{y, 0}, -1, 1}]

Say, that we want the dot going around a circle instead! We add another
control t to fix that, and let that control take over Autorun :

Manipulate[
If[t > 0, x = Cos[t]; y = Sin[t]; color = Red, color = Black];
Graphics[{color, Disk[{x, y}, 0.1]},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}], {{color,
Black}, {Black -> "Black", Red -> "Red"}}, {{x, 0}, -1,
1}, {{y, 0}, -1, 1}, {t, 0, 4*Pi}, AutorunSequencing -> {{4, 10}}]

If we test the Autorun, we see a jitter in the other controls, since they
are reset to their default whenever they are changed by t. The processor
will be occupied by changing the controls back and forth. Moreover, the
color control is locked up when Autorun is inactive. Can we fix that? Yes,
we might control the other parameters without jitter if we control their
default values dynamically. We might check if we are in the Autorun mode by
testing the variable  Typeset`bookmarkMode\$\$. The variable t has also been
changed to run stepwise.

Manipulate[
If[Typeset`bookmarkMode\$\$ === "Autorun",
If[t < 2*Pi, color1 = Red, color1 = Black]; x1 = Cos[t];
y1 = Sin[t]];
Graphics[{color, Disk[{x, y}, 0.1]},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}],
Control[{{x, Dynamic[x1], "x"}, -1, 1}],
Control[{{y, Dynamic[y1], "y"}, -1, 1}],
Control[{{color, Dynamic[color1], "color"}, {Black -> "Black",
Red -> "Red"}}], Control[{{t, 0}, 0, 4*Pi, Pi/12}],
AutorunSequencing -> {{4, 10}},
Initialization :> {color1 = Black; x1 = 0.; y1 = 0.}]

Can we have the control for t invisible? Note the uncommon programming
construction "If[False,...". In this embedding the control for t will never
show up, but it is anyway found by the AutorunSequencing as the fourth
control.

Manipulate[
If[Typeset`bookmarkMode\$\$ === "Autorun",
If[t < 2*Pi, color1 = Red, color1 = Black]; x1 = Cos[t];
y1 = Sin[t]];
Graphics[{color, Disk[{x, y}, 0.1]},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}],
Control[{{x, Dynamic[x1], "x"}, -1, 1}],
Control[{{y, Dynamic[y1], "y"}, -1, 1}],
Control[{{color, Dynamic[color1], "color"}, {Black -> "Black",
Red -> "Red"}}],
Dynamic[If[False, Control[{{t, 0}, 0, 4*Pi, Pi/12}],
Pane[" ", {0, 0}]]], AutorunSequencing -> {{4, 10}},
Initialization :> {color1 = Black; x1 = 0.; y1 = 0.}]

The corresponding notebook might be available at
http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb

Best regards

Ingolf Dahl

```

• Prev by Date: Re: Absolute value
• Next by Date: Re: Question Re PolarPlot Curve Printouts from Mathematica
• Previous by thread: Re: Elliptical gear calculations
• Next by thread: Re: Customizing Manipulate's Autorun