Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
Look up ParametricPlot[]. –  J. M. Jun 12 '13 at 16:38
    
This might help, the answer achieves a similar effect (in 3D). Also, it links to other, similar questions in the comments of the question. mathematica.stackexchange.com/questions/26636/… –  Ghersic Jun 12 '13 at 16:47

2 Answers 2

up vote 5 down vote accepted
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

share|improve this answer
    
Thanks, this is exactly what I was looking for. –  Michael Ray Jun 13 '13 at 13:13

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

share|improve this answer
2  
I don't get to see the polar (Keplerian) form everyday, so +1 for that. :) –  J. M. Jun 12 '13 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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