I have designed some custom colormaps. I also want to use the inbuilt colormaps as well. The user will be given a choice to select whether to use a built-in colormap or a custom one. Based on the selection the corresponding drop-down menu will be displayed and the user should be able to select the desired colormap.
Below is what I am up to now.
makeColorFn[colors_, opacities_, vars_] :=
Transpose[{vars, MapThread[Append, {colors, opacities}]}] /.
body_ :> (Blend[body, #] &)
getcolors[n_, colorspace_] := (
a = 0.8 +1.2 n;
points =
N[Transpose[
Table[{Sqrt[1 - t^2] Cos[a \[Pi] t],
Sqrt[1 - t^2] Sin[a \[Pi] t], t}, {t, -1, 1, 2/(n - 1)}]]];
pointsscaled = Rescale[points];
Switch[colorspace,
"LAB",
LABColor @@@
Transpose[{Rescale[points[[3]]], points[[1]], points[[2]]}],
"LUV",
LUVColor @@@
Transpose[{Rescale[points[[3]]], points[[1]], points[[2]]}],
"LCH",
LCHColor @@@
Transpose[{pointsscaled[[3]], pointsscaled[[1]],
pointsscaled[[2]]}]
]
)
Manipulate[
colors = getcolors[n, colorspace];
opacities = ConstantArray[1., n];
keyintensities = Table[i, {i, 0, 1, 1/(n - 1)}];
Switch[colormap, 0, ColorData[builtincolormap, "Image"], 1,
ImageCrop[
ArrayPlot[{Range[0, 1, 1/255]}, Frame -> False,
AspectRatio -> Full, ImageSize -> {261, 32},
ColorFunction ->
makeColorFn[colors, opacities, keyintensities]]]], {{colormap, 0,
"Color Map"}, {0 -> "Built-in", 1 -> "Custom"},
ControlType -> RadioButtonBar},
{{builtincolormap, "CMYKColors",
"Built-in Color Map"}, {"CMYKColors",
"BlueGreenYellow", "DarkRainbow", "VisibleSpectrum"}},
{{n, 3, "Number of Colors"}, 2, 20, 1,
ControlType -> PopupMenu}, {{colorspace, "LAB",
"Color Space"}, {"LAB", "LUV", "LCH"}},
ControlPlacement -> Left]
The code is working fine. However, my problem is that I cannot dynamically control the visibility of the controls for built-in and the custom color functions. How can I control the output such that only the corresponding controls will be visible dynamically?
[Bonus: It will be a bonus to display the custom colormaps in the same way as the built-in colormaps are displayed.]