From: Ingolf Dahl on
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(a)telia.com.
The corresponding notebook might be available at
http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb

Best regards

Ingolf Dahl


From: John Fultz on
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(a)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(a)telia.com.
> The corresponding notebook might be available at
> http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb
>
> Best regards
>
> Ingolf Dahl



From: Ingolf Dahl on
Thanks for the comments!
Yes, I have considered setting bookmarks and use bookmark animation.
However, the demonstration I presently am trying to develop is a bit more
complicated that the example I gave in the letter. It works in all other
ways than bookmark animation, but when I ask for "Animate bookmarks"
Mathematica runs havoc, and I get a pink mess of errors. One of the first
errors is

ListPlot::lpn:
Interpolation[{{{-2.,-2.},{2.4,-2.},{2.,2.},{-4.08998,1.42527},{-1.02122,4.2
2125},{-0.339269,0.64103}},<<3>>,{{-2.,-2.},{2.4,-2.},{2.,2.},{-4.08998,1.42
527},{-1.02122,4.22125},{-0.339269,0.64103}}},InterpolationOrder->0][4.39874
7253417969`] is not a list of numbers or pairs of numbers.

I also get

Interpolation::indim: "\!\(\*
StyleBox[\"\\\"The coordinates do not lie on a structured tensor product
grid.\\\"\", \"MT\"]\) "

I think this is a bug. I believe that the intension is to have implicit
coordinate positions for the interpolation, with a list only of function
values, Interpolation[{f1, f2, f3,...}]. In this case, the function values
are point lists. (The point lists are of variable length, but that does not
matter here and now.) But Mathematica thinks that we try to construct an
interpolation of multidimensional data, and protests, because the points do
not lie on a structured tensor product grid.

When bookmark animation did not work for me, I concentrated on understanding
Autorun, since even if bookmark animation had worked, I am not sure that I
would be satisfied with it. As I see it, the bookmark animation is like
ready-made clothing: when it fits, it fits, and when it works, it works, but
sometimes a real tailor is needed.

The second suggestion about "ControlType -> None" I have inserted into the
notebook. Not as fun as my "If[False,..." construction, but a more proper
programming solution.

I will update the notebook at
http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb
further, if I get more good suggestions.

Best regards

Ingolf Dahl

> -----Original Message-----
> From: John Fultz [mailto:jfultz(a)wolfram.com]
> Sent: den 29 juni 2010 14:28
> To: mathgroup(a)smc.vnet.net
> Subject: Re: Customizing Manipulate's Autorun
>
> 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(a)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(a)telia.com.
> > The corresponding notebook might be available at
> > http://www.familydahl.se/mathematica/CustomizingManipulatesAutorun.nb
> >
> > Best regards
> >
> > Ingolf Dahl
>



From: Ingolf Dahl on
Here is a second comment on John Fultz's comments on my letter:

> From: John Fultz [mailto:jfultz(a)wolfram.com]

> snip

> 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

When I read this, I thought I must have missed something in the
documentation. So I became a little bit finicky and checked the
documentation. This is what I have found, relating Control and ControlType:

On the "Control Objects" page: " Control -- an interactive control with type
automatically chosen", and ControlType is not mentioned.

On the " Controls Options" page: ControlType is not mentioned.

On the "Control" page, "opts" is mentioned as a possible argument with the
comment " use the specified control options". But then no possible option
are specified or used in the examples.

On the "ControlType" page: "ControlType is an option for Manipulate and
related functions that specifies what type of controls should be displayed".
Please be specific and tell the names of the "related functions"! It is not
easy to understand that Control is a related function, while Manipulator is
not. Or can ControlType be given as option to Manipulator?

In the "Introduction to Manipulate" and the "Advanced Manipulate
Functionality": Neither Control nor ControlType is mentioned, as far as I
have found when I scanned through. Have I missed some place?

Finally, at the "Manipulate" page, both Control and ControlType are
mentioned, and it is stated "ControlType options can be given separately for
each variable. Options for the controls can also be given within the
specification for the variables." This was what I missed.

It is not explicitly stated, but I guess that it is so, that the argument of
Control should have the same form as the specification of a variable for
Manipulate. A variable for Manipulate is considered as an variable for
Manipulate even if it is wrapped by a Control statement. Are there any
examples of Manipulate using Control as argument? Control has also an own
life outside Manipulate, but then ControlType->None does not seem to be an
option.

So I do not think I am unfair if I describe the use of Control with the
option ControlType->None as an "undocumented, or poorly documented feature".
One thing that might be clarified is what the difference is between the
setting {{u,0}, None} and {{u,0}, ControlType->None} or setting u = 0 in the
Initialization option.

Ingolf Dahl


From: John Fultz on
On Thu, 1 Jul 2010 07:24:20 +0200, Ingolf Dahl wrote:
> Here is a second comment on John Fultz's comments on my letter:
>
>> From: John Fultz [mailto:jfultz(a)wolfram.com]
>>
>> snip
>>
>> 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
>>
> When I read this, I thought I must have missed something in the
> documentation. So I became a little bit finicky and checked the
> documentation. This is what I have found, relating Control and
> ControlType:
>
> On the "Control Objects" page: " Control -- an interactive control with
> type automatically chosen", and ControlType is not mentioned.
>
> On the " Controls Options" page: ControlType is not mentioned.
>
> On the "Control" page, "opts" is mentioned as a possible argument with
> the comment " use the specified control options". But then no possible
> option are specified or used in the examples.
>
> On the "ControlType" page: "ControlType is an option for Manipulate and
> related functions that specifies what type of controls should be
> displayed". Please be specific and tell the names of the "related
> functions"! It is not easy to understand that Control is a related
> function, while Manipulator is not. Or can ControlType be given as option
> to Manipulator?
>
> In the "Introduction to Manipulate" and the "Advanced Manipulate
> Functionality": Neither Control nor ControlType is mentioned, as far as I
> have found when I scanned through. Have I missed some place?
>
> Finally, at the "Manipulate" page, both Control and ControlType are
> mentioned, and it is stated "ControlType options can be given separately
> for each variable. Options for the controls can also be given within the
> specification for the variables." This was what I missed.
>
> It is not explicitly stated, but I guess that it is so, that the argument
> of Control should have the same form as the specification of a variable
> for Manipulate. A variable for Manipulate is considered as an variable
> for Manipulate even if it is wrapped by a Control statement. Are there
> any examples of Manipulate using Control as argument? Control has also an
> own life outside Manipulate, but then ControlType->None does not seem to
> be an option.
>
> So I do not think I am unfair if I describe the use of Control with the
> option ControlType->None as an "undocumented, or poorly documented
> feature". One thing that might be clarified is what the difference is
> between the setting {{u,0}, None} and {{u,0}, ControlType->None} or
> setting u == 0 in the Initialization option.
>
> Ingolf Dahl

This example would have worked without Control. My use was superfluous, and I
included it principally because your example included it. So, this syntax does
the same thing...

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

I will certainly concede that the documentation has weaknesses, some of which
have been pointed out ad nauseum on this forum. Drawing specific conclusions
about the usefulness of ControlType->None is among them. But the usage of the
ControlType option to customize individual Manipulate variables is really quite
prominently documented on the Manipulate reference page and the Introduction to
Manipulate tutorial.

However, in my hurry to dash off a response, I probably would have been more
tentative about ControlType->None specifically being documented if I hadn't
misinterpreted some examples in my haste. I don't think I would say now that
there are "several examples" documenting this (there is one, but it's not
anyplace you would think to look, and does not demonstrate why this is useful).
I would say that you can connect the dots for using None as a ControlType, but
concede that the dots may not be so easy to connect. I apologize for suggesting
otherwise.

Speaking of Control[] generally, I noticed a number of months ago that Control[]
is pretty under-documented given its import. It's an incredibly powerful,
useful, and easy-to-use construct for putting together Manipulates with
customized interface appearances. While the core information to do this is
generally available (except curiously, as you point out, the fact that Control
exactly analogizes Manipulate variable syntax), too much is left to the reader
to infer rather than spelled out in a clear and useful way. That will be fixed.
And I'll look into dealing with ControlType->None in the documentation as well.

Sincerely,

John Fultz
jfultz(a)wolfram.com
User Interface Group
Wolfram Research, Inc.