I've created a piece of code that returns random color scheme:

getRandomColor = ColorData["Gradients"][[RandomInteger[{1, 51}]]]

Now, I'm trying to use it with my Manipulate, ArrayPlot, to generate random color schemes to be applied to the plot:

 ArrayPlot[SierpinskiCarpet@iterations, Frame -> False, 
  ColorFunction -> color],
 {iterations, 1, 5, 1, Appearance -> "Labeled"},
 {color, {"AlpineColors", "ArmyColors", 
   blackAndWhite -> "Black & White", getRandomColor -> "Random"}}]

It does work only once, then it doesn't reevaluate the color, on Random button click, but sticks with the value, that was generated on the first click. How to cope with that?

  • $\begingroup$ Thanks! You may want to post it as an answer! $\endgroup$
    – Elias
    Dec 16 '16 at 10:51
  • $\begingroup$ Yes, I did notice that. Also, there is the thing that when I slide the slider, the function gets triggered on each slider's step. I wouldn't say that it's a good thing, it's definitely not what I expected, but it's not a crucial bug for me nonetheless. $\endgroup$
    – Elias
    Dec 16 '16 at 13:02
getRandomColor[] := ColorData["Gradients"][[RandomInteger[{1, 51}]]]

 Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> color], 
 {color, {"AlpineColors", "ArmyColors", "Random"}, 
  TrackingFunction :> ((color = If[# === "Random", getRandomColor[], #]) &)

Feel free to ask if anything is not clear.


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.