Java examples for 2D Graphics:Color RGB
Converts a scalar normalized to de range [0:1] into a long rainbow of rgba values.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { float value = 2.45678f; float[] rgba = new float[] { 34.45f, 35.45f, 36.67f, 37.78f, 37.0000f, 37.1234f, 67.2344f, 68.34534f, 69.87700f }; long_rainbow(value, rgba); }//from w ww.j ava2 s .com /** * Converts a scalar normalized to de range [0:1] into * a long rainbow of rgba values. * See: http://www.particleincell.com/blog/2014/colormap/ * @param value * @return */ public static void long_rainbow(float value, float[] rgba) { /*plot long rainbow RGB*/ float a = (1 - value) / 0.2f; //invert and group final int X = (int) Math.floor(a); //this is the integer part float Y = (a - X); //fractional part from 0 to 1 rgba[3] = 1; switch (X) { case 0: rgba[0] = 1; rgba[1] = Y; rgba[2] = 0; break; case 1: rgba[0] = 1 - Y; rgba[1] = 1; rgba[2] = 0; break; case 2: rgba[0] = 0; rgba[1] = 1; rgba[2] = Y; break; case 3: rgba[0] = 0; rgba[1] = 1 - Y; rgba[2] = 1; break; case 4: rgba[0] = Y; rgba[1] = 0; rgba[2] = 1; break; case 5: rgba[0] = 1; rgba[1] = 0; rgba[2] = 1; break; } } }