I wrote something to do something a little like what you wanted. Here I've adapted it so you can get a run through for each setting of the SetterBar
. Some description of the functions.
autolist[control_pattern] :=
list of manipulate settings for the animation
specs
is a pattern for culling variable specifications out of a Manipulate
rulefunction[variable_spec]
yields a rule for injecting a setting into a Manipulate
steps[man, sequence, frames]
creates an animation of the Manipulate
code man
by animating the controls in sequence
by interpolating over a number of frames
, which can be a list the number of frames for each control (in order of the controls). The argument sequence
has the form
{{i11, i12,...}, {i22,...},...}
For each setting of the controls in the first list, the controls in the second list run through there settings and so forth (like the iterators of Table
).
specs = HoldPattern[Manipulate[body_, stuff___]] :>
Cases[Hold[stuff], sp_List :> Hold[sp], {1}];
rulefunction[spec : {{var_, i_, label___}, __} | {var_, __}] :=
HoldPattern[{_?(MemberQ[{#}, HoldPattern[var], 2] &), rest___}] :> {{var, #,
label}, rest} &;
(*Manipulator*)
autolist[Hold[
spec : {var_, min_?NumericQ, max_?NumericQ, opts : OptionsPattern[]}],
nFrames_: 20] := Module[{init},
init = If[Head[var] === List, var[[2]], min];
Map[
rulefunction@spec,
Interpolation[
Transpose[{Range[0, 1,
1/(Length[#] - 1)], #}] &@(DeleteDuplicates[{init, max, min}]~
Append~init),
InterpolationOrder -> 1]@Rescale@N@Range@nFrames
]
];
(*SetterBar/PopupMenu*)
striplabels[data : {__Rule}] := First /@ data;
striplabels[data_] := data
autolist[Hold[spec : {var_, data_List, opts : OptionsPattern[]}],
nFrames_: 20] :=
Map[
rulefunction@spec,
striplabels[
data][[Clip[
Round[Rescale[#, {0, 1}, {0.5, Length@data + 0.5}]], {1,
Length@data}]]] &@Rescale@N@Range@Ceiling[nFrames, Length@data]
];
(*skip anything else - add more cases to handle other controls*)
autolist[__] := {};
Clear[steps];
steps[man_, seq : {__List}, frames_: 20] :=
With[{specifications = (man /. specs)[[First[seq]]]},
Table[steps[Replace[man, setting, 1], Rest[seq], frames], {setting,
Flatten[MapThread[
autolist, {specifications,
If[Head[frames] === List, frames[[First[seq]]],
ConstantArray[frames, Length@specifications]]}]]}]
];
steps[man_, {}, ___] := man;
Export["1Example.gif", #] &@
With[{man =
Manipulate[
Plot[{Sin[a*x] + b*Cos[3 a*x], k*x}, {x, 0, \[Pi]}], {a, 1, 2}, {b, 0,
1}, {k, {0, 0.5, 1}}],
frames = {20, 20, 3}},
Module[{seq},
seq = {{3}, {1, 2}};
Flatten[
steps[man, seq, frames],
Length[seq] - 1]
]
]
AutorunSequencing
? $\endgroup$