Sign in to follow this  
Saurabh Dixit

color variation with values

Recommended Posts

I am making a visualization software in which I am representing my data values by spheres. I want to vary the color of those spheres with value of thoes datas. So I need a way to manupulate the data values in some way so that their is a smooth variation of color(in RGB mode).I am using glcolorf() for coloring. Like blue for low values and red for higher .....If anybody knows how to do it plz help me.

Share this post


Link to post
Share on other sites
Not sure what you mean. Sounds like all you need to do is take some value from your data set, scale that between 0 and 1, and use that scaled value as one of the inputs to glColor3f. If you have multiple values you could extract from the data set you can do it for all three color components, although that can tend to get busy.

Share this post


Link to post
Share on other sites
Yes its the same I want to show my values by spheres with the color according to value .

But I want something so that the lowest value corresponds to blue color and red to high.

Share this post


Link to post
Share on other sites
In RGB space, interpolate the R and B channels from 0 to 1 according to the value. Scale the interpolation by some arbitrary factor until you get the results you like (alternatively, invert one, or quantize them, so that the red component is not altered until the value is above a certain threshold, et cetera). Just experiment with the scaling or quantization factors until things look the way you want.

Other options include converting to a hue-based color space, and linearly interpolating the hue component (which conveniently is linear between blue/purple/red from about hue angle 240 to 360 in HSB or HSL).

Share this post


Link to post
Share on other sites
You can do something like :

maxValue = 100; //the maximum value that can be in the dataset
minValue = 10; //min value in the dataset.just made up these numbers.
value = 50;

normalized = (value - minValue)/(maxValue-minValue);

glColor3f(normalized,0.0f, 1.0f - normalized);

Not tested so It may not work and you may need to do some bounds checking and clamping.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this