I need to visualize a list of numbers, this list is generated every x minutes. I currently use a single line with numbers at the side. This works correctly, but while doing live analysis it becomes hard on the eyes.
After thinking a bit i came up with the idea of color coding the numbers, a large negative number is red and a large positive number is green, a normal positive number is light green, slightly bigger than normal number sits between green and light green.
To illustrate it i made a image:
To my question. If for example we have:
50: Color.green
0: Color.white
-50: Color.red
How can i calculate the color that represents 25?
For strictly linear representation between red <--> white <--> green
,
import java.awt.Color;
/* Define the MAXIMUM saturation of RED and GREEN shades
* Range (0-255)
*/
final int RED_MAX = 255;
final int GREEN_MAX = 255;
/* input val varies from -MAX to MAX */
/* output valColor varies from
* -MAX = red
* ^
* |
* v
* 0 = white
* ^
* |
* v
* MAX = green
*/
/* Normalised normVal varies from -255 to 255 */
normVal = (val*255)/MAX
if(val < 0) {
/* Make it red-ish */
valColor = new Color( RED_MAX,
255 + normVal,
255 + normVal );
} else if (val > 0) {
/* Make it green-ish */
valColor = new Color( 255 - normVal),
GREEN_MAX,
255 - normVal );
} else {
/* Absolute White */
valColor = new Color( 255, 255, 255 );
}
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