c# rgb colour scale -
i have requirement display particular colour representation dependant upon data. @ 1 end of scale green , other red. scale should cover colours in between.
i comfortable actual programming, unsure of how scale rgb colours. know scales sort of thing?
thanks.
the following method should work :
color getcolor(int32 rangestart /*complete red*/, int32 rangeend /*complete green*/, int32 actualvalue) { if (rangestart >= rangeend) return colors.black; int32 max = rangeend - rangestart; // make scale start 0 int32 value = actualvalue - rangestart; // adjust value accordingly int32 green = (255 * value) / max; // calculate green (the closer value max, greener gets) int32 red = 255 - green; // set red inverse of green return color.fromrgb((byte)red, (byte)green, (byte)0); }
Comments
Post a Comment