I have a requirement to display a particular colour representation dependant upon data. At one end of the scale is green and the other red. The scale should cover the colours in between.
I am comfortable with the actual programming, but unsure of how to scale the rgb colours. Does anybody know any scales for this sort of thing?
Thanks.
The following method should work for you :
Color GetColor(Int32 rangeStart /*Complete Red*/, Int32 rangeEnd /*Complete Green*/, Int32 actualValue)
{
if (rangeStart >= rangeEnd) return Colors.Black;
Int32 max = rangeEnd - rangeStart; // make the scale start from 0
Int32 value = actualValue - rangeStart; // adjust the value accordingly
Int32 green = (255 * value) / max; // calculate green (the closer the value is to max, the greener it gets)
Int32 red = 255 - green; // set red as inverse of green
return Color.FromRgb((Byte)red, (Byte)green, (Byte)0);
}
Is this what you mean?
Color GetColor(int scale)
{
// scale is between 1 and 255
return Color.FromArgb(255, scale, 255 - scale, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With