Mega Code Archive

 
Categories / Java / 2D Graphics GUI
 

Returns blue-yellow-red color scale

/**  * Utilities for GUI work.  * @author Alex Kurzhanskiy  * @version $Id: UtilGUI.java 38 2010-02-08 22:59:00Z akurzhan $  */ import java.awt.Color; public class Util {   /**    * Returns blue-yellow-red color scale.    */   public static Color[] byrColorScale() {     int[][] rgb = {         {0, 0, 0},         {0, 0, 159},         {0, 0, 191},         {0, 0, 223},         {0, 0, 255},         {0, 32, 255},         {0, 64, 255},         {0, 96, 255},         {0, 128, 255},         {0, 159, 255},         {0, 191, 255},         {0, 223, 255},         {0, 255, 255},         {32, 255, 223},         {64, 255, 191},         {96, 255, 159},         {128, 255, 128},         {159, 255, 96},         {191, 255, 64},         {223, 255, 32},         {255, 255, 0},         {255, 223, 0},         {255, 191, 0},         {255, 159, 0},         {255, 128, 0},         {255, 96, 0},         {255, 64, 0},         {255, 32, 0},         {255, 0, 0},         {223, 0, 0},         {191, 0, 0},     };     return getColorScale(rgb);   }   /**    * Returns n-dimensional array of colors for given nx3 integer array of RGB values.     */   public static Color[] getColorScale(int[][] rgb) {     if (rgb == null)       return null;     Color[] clr = new Color[rgb.length];     for (int i = 0; i < rgb.length; i++) {       float[] hsb =  Color.RGBtoHSB(rgb[i][0], rgb[i][1], rgb[i][2], null);       clr[i] = Color.getHSBColor(hsb[0], hsb[1], hsb[2]);     }     return clr;   } }