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.

This question already has an answer here:

Suppose p is a some point in the plane. The function f[q] defined as

f[q_]:= Block[{d = Norm[p-q]}, RGBColor[1 - d/(1 + d), 0, d/(1 + d)]]

Continuously colors points in the plane by thier distance from p. What is the easiest way to plot this in 2D? I tried DensityPlot but that's not exactly what I'm looking for. Basically I want to specify some color function for points in the plane and plot it. Contours would be a bonus.

Apologies if this exact question has been asked before.

share|improve this question

marked as duplicate by Öskå, Artes, Sjoerd C. de Vries, RunnyKine, Mr.Wizard Aug 14 at 21:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I guess you are looking for something like this Coloring a shape according to a function. –  Artes Aug 14 at 16:49
    
Yes. I think that will work. RegionPlot looks like the solution. Mebbe I should delete this question. –  amcalde Aug 14 at 16:51
    
OK I can't get this to work for a simple example. I put p = {2,3}, f as above, then RegionPlot[True, {x, 1, 4}, {y, 1, 4}, ColorFunction -> Function[{x, y}, f@{x, y}]] Doesn't work, gives a solid square. –  amcalde Aug 14 at 18:35
1  
Add ColorFunctionScaling->False to your plot and see if that does what you'd like. –  bobthechemist Aug 14 at 19:33
    
That did it, thaks @bobthechemist! –  amcalde Aug 14 at 19:35

1 Answer 1

up vote 5 down vote accepted

Just for fun, try this

ControllerManipulate[
 RegionPlot[True, {x, 1, 4}, {y, 1, 4}, ColorFunctionScaling -> False,
   ColorFunction -> 
   Function[{x, y}, 
    Block[{d = Norm[l - #]}, 
       RGBColor[1 - d/(1 + d), 0, d/(1 + d)]] & @{x, y}]], {{l, {2, 
    2}}, Locator, Appearance -> None}]

enter image description here

share|improve this answer

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