4
$\begingroup$

I would like to create a $2D$ shape, say an ellipse, where each point in the ellipse is colored according a RGB function, so at point x and y the color would be:

RGBColor[ u[x,y], v[x,y], w[x,y]]

I am sure there has to be an easy way to do this, but I have not had much luck.

$\endgroup$
8
$\begingroup$
u[x_, y_] := Sin[x] + Cos[y]
v[x_, y_] := E^-x + y
w[x_, y_] := Tanh[x] + Sqrt[y]
RegionPlot[2 x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1}, Mesh -> None,
ColorFunction -> Function[{x, y}, RGBColor[u[x, y], v[x, y], w[x, y]]]]

Result: resulting plot

$\endgroup$
  • 1
    $\begingroup$ Thanks, this is exactly what I was looking for. $\endgroup$ – Michael Ray Jun 13 '13 at 13:13
6
$\begingroup$

Let's use a polar formula for a conic curve,

cc[u_, eps_] := {1/(1 + eps Cos[u]) Cos[u], 1/(1 + eps Cos[u]) Sin[u]}

For -1 < eps < 1 we have an ellipse, for eps == 1 a parabola, and for eps > 1 a hyperbola.

We assume a simple function to describe dependence of the color on the angle:

ParametricPlot[ cc[u, 2/3], {u, 0, 2 Pi}, Axes -> False, PlotStyle -> Thick, 
                ColorFunction -> Function[{x, y, u}, Hue[u/(2 Pi)]], 
                ColorFunctionScaling -> False]

colored ellipse

ParametricPlot[ cc[u, 1], {u, 0, 2 Pi}, Axes -> False, PlotStyle -> Thick, 
                ColorFunction -> Function[{x, y, u}, Hue[u/(2 Pi)]], 
                ColorFunctionScaling -> False] 

enter image description here

and to plot a hyperbola we'd use Exclusions (to get rid of zero from the denominator) e.g.

ParametricPlot[ cc[u, 3/2], {u, 0, 2 Pi}, Axes -> False, PlotStyle -> Thick, 
                ColorFunction -> Function[{x, y, u}, Hue[u/(2 Pi)]], 
                ColorFunctionScaling -> False, Exclusions -> {Cos[u] == 2/3, Cos[u] == -2/3}]

enter image description here

$\endgroup$
  • 2
    $\begingroup$ I don't get to see the polar (Keplerian) form everyday, so +1 for that. :) $\endgroup$ – J. M. will be back soon Jun 12 '13 at 17:16

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.