Background: The following snippet is what I (intend to) use in a Manipulate
form where up to 12 different colors can be selected:
Manipulate[{sliderCol1},
Row[{"Kleur 1: ", ColorSlider[
Dynamic[sliderCol1] ,
AppearanceElements -> {"SwatchSpectrum"},
ImageSize -> {200, 40},
BaselinePosition -> Scaled[.25]]}
]
]
To make this work with fields sliderCol1
to sliderColn
(where $n$ = 2, …, 12), I see no other option than copying the code in Row
so many times.
Question: Is there a less verbose way of implenting a multiple (here 12) color selector using color sliders?
Answer
With this one you just click the circle to be color-edited. No need to pick an index number first.
DynamicModule[{x = 1},
Manipulate[c[[x]] = color;
Grid[
Table[
Setter[Dynamic[x, (color = c[[#1]]; x = #1) &], i*4 + j,
Graphics[{FaceForm[c[[i*4 + j]]], Disk[]}, ImageSize -> 40]
], {i, 0, 2}, {j, 4}
]
], {color, Red},
Initialization :> {c = ConstantArray[Black, 12]}]
]
Note that I used Dynamic
's alternative syntax form, where you determine what should happen if the argument needs to be updated. In this case I use it to set the starting color of the color selector to be the current color of the circle being clicked. Otherwise the color of the circle would be set by the current setting of the color setter. This may be or may not be how you want the control to behave. Just change it to Dynamic[x]
if you want to have the other behavior.
Comments
Post a Comment