# color variation with values

This topic is 4000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 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.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
18

• 11
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×