MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Customizing Manipulate's Autorun

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110632] Re: Customizing Manipulate's Autorun
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Tue, 29 Jun 2010 08:27:30 -0400 (EDT)
  • Reply-to: jfultz at wolfram.com

Two comments...

First, did you consider setting bookmarks and animating through them instead of 
using the autorun functionality?  This is well-documented and generally easier 
to puzzle out than the approach you took, I think.  The bookmarks serve as 
keyframes which you can animate between.  Something like this...

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}, 
 Bookmarks -> {"frame1" :> (x = 1; y = 0; color = Black), 
   "frame2" :> (x = 0; y = -1; color = Red), 
   "frame3" :> (x = -1; y = 0; color = Red), 
   "frame4" :> (x = 0; y = 1; color = Black), 
   "frame5" :> (x = 1; y = 0; color = Black)}]

Then choose "Animate Bookmarks" instead of "Autorun".

Second, there is a much easier technique for making a hidden control.  
Manipulate supports this directly using the ControlType option.  E.g.,

Control[{{t, 0}, 0, 4*Pi, Pi/12, ControlType -> None}]

There are several examples in the Manipulate documentation which highlight this 
usage.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Tue, 29 Jun 2010 06:58:55 -0400 (EDT), Ingolf Dahl wrote:
> 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.}]
>
> Please send comments to ingolf.dahl at telia.com.
> The corresponding notebook might be available at
> http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb
>
> Best regards
>
> Ingolf Dahl




  • Prev by Date: Exporting a List of Tables with different Lengths to a tabulator
  • Next by Date: Re: numerical integration
  • Previous by thread: Customizing Manipulate's Autorun
  • Next by thread: Re: Customizing Manipulate's Autorun