2
$\begingroup$

I have a function that takes in two numbers and returns a RGB color. I would like to plot that function on a 2D surface. How can I do that?

$\endgroup$
  • $\begingroup$ Where is the function? $\endgroup$ – J. M. will be back soon Oct 25 '15 at 15:57
  • $\begingroup$ ColorFunction? $\endgroup$ – Michael E2 Oct 25 '15 at 15:59
  • $\begingroup$ @J. M. ChromaticityPlot["RGB"]; {x, y, z} = Interpolation[ Thread[{Image``ColorOperationsDump``$wavelengths, #}]] & /@ Transpose[Image``ColorOperationsDump``tris]; , XYZClipped[S_, E_] := NIntegrate[{x[l], y[l], z[l]}, {l, S, E}]/ NIntegrate[x[l] + y[l] + z[l], {l, S, E}]. The function I want to plot is XYZColor[XYZClipped[S,E]] from 400 to 700. $\endgroup$ – abcd1234 Oct 25 '15 at 15:59
  • $\begingroup$ That returns an XYZ color, not an RGB color. You could probably use Table[] and Image[] for this. $\endgroup$ – J. M. will be back soon Oct 25 '15 at 16:07
1
$\begingroup$

Use RegionPlot with ColorFunction. It is important to use ColorFunctionScaling -> False otherwise your function will be given modified x and y values.

RegionPlot[
 True, {x, -1, 1}, {y, -1, 1},
 ColorFunction -> Function[{x, y}, GrayLevel@Norm[{x, y}]],
 ColorFunctionScaling -> False,
 BoundaryStyle -> None
 ]

Mathematica graphics

If your color function is a linear interpolation based on some "sources" you can use VertexColors. The example from the documentation is

Graphics[Polygon[{{-1, 0}, {1, 0}, {0, Sqrt[3]}}, VertexColors -> {Red, Green, Blue}]]

Mathematica graphics

And of course you can also sample your points and create an image manually. For example

pixels = Table[
   GrayLevel@Norm[{x, y}],
   {x, -1, 1, 0.01}, {y, -1, 1, 0.01}
   ];
Image[pixels]

Mathematica graphics

$\endgroup$

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