8
$\begingroup$

I would like to create dynamically buttons in Manipulate in such a way that after clicking the button the Manipulate parameters would come back to the values when the button was created. In my example after pressing "Save params" button I would like to add new button to Row with thumbnail of ParametricPlot with current set of parameters.

Manipulate[
 ParametricPlot[{Sin[a*u], Sin[b* u]}, {u, 0, c Pi}],
  Row[{
   Button[ParametricPlot[{Sin[2*u], Sin[3* u]}, {u, 0, 2 Pi}, ImageSize -> {30, 30}, Axes -> False], a = 2; b = 3; c = 2, ImageSize -> {50, 50}],
   Button[ParametricPlot[{Sin[5*u], Sin[6 u]}, {u, 0, 2 Pi}, ImageSize -> {30, 30}, Axes -> False], a = 5; b = 6; c = 2, ImageSize -> {50, 50}]
  }],
 {a, 1, 10},
 {b, 1, 10},
 {c, 1, 10},
 Button["Save params"]
]
$\endgroup$
10
$\begingroup$

Here's my go at it. I used a SetterBar with a Dynamic list of presets, since it implements a dynamic row of buttons for me. By not assigning a value to set, the button won't be highlighted, but clicking the button will have the desired action.

Manipulate[
 ParametricPlot[{Sin[a*u], Sin[b*u]}, {u, 0, c Pi}, PlotRange -> 1],
 {{presets, {{2, 3, 2} -> 
     ParametricPlot[{Sin[2*u], Sin[3*u]}, {u, 0, 2 Pi}, 
      ImageSize -> {30, 30}, Axes -> False],
    {5, 6, 2} -> 
     ParametricPlot[{Sin[5*u], Sin[6 u]}, {u, 0, 2 Pi}, 
      ImageSize -> {30, 30}, Axes -> False]}},
  ControlType -> None},
 {set, Dynamic@presets, SetterBar, 
  TrackingFunction -> (((*set=*){a, b, c} = #) &)},
 {a, 1, 10}, {b, 1, 10}, {c, 1, 10},
 Button["Save params", 
  AppendTo[presets, {a, b, c} -> 
    ParametricPlot[{Sin[a*u], Sin[b*u]}, {u, 0, c Pi}, PlotRange -> 1,
      ImageSize -> {30, 30}, Axes -> False]]]
 ]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.