0
$\begingroup$

I would like to generate a color function from the dynamic panel code and use it as I want...instead of using Copy to Clip Board and then past in myTM.... Any idea ? I dont want to use Copy and past in myTM, I would like to use directly the results from the dynamic panel without any click

Here my code

(*Dynamic panel*)
With[{cmax = 12},(*maximum number of colors*)
 DynamicModule[{k = 5, cols = {White, LightBlue, Yellow, Orange, Red},
    vals = {0, 0.35, 0.75, 0.95, 1}}, 
  Panel[Column[{Column[{Row[{Dynamic[
          Style["colors: " <> IntegerString[k], Bold]], Spacer[20], 
         Slider[Dynamic[k, (k = #; cols = PadRight[cols, k, Gray];

             vals = Rescale[
               ArrayPad[vals, {0, k - Length[vals]}, 
                "Extrapolated"]]) &], {2, cmax, 1}]}], 
       Dynamic[Multicolumn[
         Array[Column[{ColorSlider[Dynamic[cols[[#]]]], 
             Row[{Dynamic[Style[vals[[#]], Small, Bold]], Spacer[20], 
               Slider[Dynamic[vals[[#]]], {0, 1}, 
                ImageSize -> Small]}]}] &, k], 5, 
         Appearance -> "Horizontal"], TrackedSymbols :> {k}]}], 
     Dynamic[With[{cl = Transpose[{vals, cols}]}, 
       Column[{Panel[
          LinearGradientImage[
           Blend[cl, Rescale[#, {0, 1}, MinMax[vals]]] &, {600, 60}]],
          Button["Copy to clipboard", 
          CopyToClipboard[Defer[Blend[cl, f]]], ImageSize -> Medium, 
          Method -> "Queued"]}]]]}]]]]

(*data*)
data = Table[{#, #2, Sin[#] Cos[#2]} & @@ 
    RandomReal[{-3, 3}, 2], {1000}];


(*MyColor function with Gamma correction*)
Table[MapAt[#^(1/\[Gamma]) &, Brown, ;; 3], {\[Gamma], {0.4, 1, 2.2}}];
    gamma[\[Gamma]_][c_?ColorQ] := 
  MapAt[#1^(1/\[Gamma]) &, ColorConvert[c, "RGB"], ;; 3];
myTM[\[Gamma]_] := 
  gamma[\[Gamma]]@
    Blend[{{0, GrayLevel[1]}, {0.35`, RGBColor[
       0.5700000000000001, 0.76, 1.]}, {0.75`, RGBColor[
       1, 1, 0]}, {0.95`, RGBColor[1, 0.5, 0]}, {1, RGBColor[
       1, 0, 0]}}, #] &(*past my color function here*);

(*My graphics*)

graph3 = ListDensityPlot[data,
  ColorFunction -> myTM[0.1],
  PlotRange -> All,
  ScalingFunctions -> {"Linear", "Linear", "Linear"},
  ImageSize -> UpTo[850]
  ]
$\endgroup$
2
  • $\begingroup$ Please describe how do you imagine the flow. Have you tried to put your definition of myTM to the button instead of CopyToClipboard? $\endgroup$
    – Kuba
    Nov 29, 2018 at 12:27
  • $\begingroup$ I edited and put the link I used to generate the dynamic color panel. My definition of my TM is a combination of a gamma function and the Blend colors function I get from the dynamic panel...How can I replace my button with myTM ? $\endgroup$ Nov 29, 2018 at 12:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.