Example usage for java.awt Color getHSBColor

List of usage examples for java.awt Color getHSBColor

Introduction

In this page you can find the example usage for java.awt Color getHSBColor.

Prototype

public static Color getHSBColor(float h, float s, float b) 

Source Link

Document

Creates a Color object based on the specified values for the HSB color model.

Usage

From source file:Main.java

public static void main(String[] args) {
    Color myColor = Color.getHSBColor(0.1F, 0.2F, 0.3F);

    System.out.println(myColor);

}

From source file:Util.java

/**
 * Returns n-dimensional array of colors for given nx3 integer array of RGB values. 
 *///from  ww  w . j  av  a 2 s .  c  o  m
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;
}

From source file:Util.java

/**
 * Returns color based on 0-9 scale ranging from black to green.
 *//*  w w w.  j  av  a  2  s  . com*/
public static Color kgColor(int i) {
    int[][] rgb = { { 21, 0, 0 }, { 99, 0, 0 }, { 177, 0, 0 }, { 255, 0, 0 }, { 255, 85, 0 }, { 255, 170, 0 },
            { 255, 255, 0 }, { 150, 225, 0 }, { 65, 194, 0 }, { 0, 164, 0 } };
    int ii = 0;
    if (i > 9)
        ii = 9;
    else
        ii = Math.max(i, ii);
    float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null);
    return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}

From source file:Util.java

/**
 * Returns color based on 0-9 scale ranging from yellow to red.
 *//*from w ww.j a  v  a  2 s.c o m*/
public static Color yrColor(int i) {
    int[][] rgb = { { 255, 202, 0 }, { 255, 180, 0 }, { 255, 157, 0 }, { 255, 135, 0 }, { 255, 112, 0 },
            { 255, 90, 0 }, { 255, 67, 0 }, { 255, 45, 0 }, { 255, 22, 0 }, { 255, 0, 0 } };
    int ii = 0;
    if (i > 9)
        ii = 9;
    else
        ii = Math.max(i, ii);
    float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null);
    return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}

From source file:Util.java

/**
 * Returns color based on 0-9 scale ranging from green to yellow.
 *///from  w ww . ja va 2  s  .  co m
public static Color gyColor(int i) {
    int[][] rgb = { { 0, 164, 0 }, { 19, 174, 0 }, { 41, 184, 0 }, { 65, 194, 0 }, { 91, 204, 0 },
            { 119, 215, 0 }, { 150, 225, 0 }, { 183, 235, 0 }, { 218, 245, 0 }, { 255, 255, 0 } };
    int ii = 0;
    if (i > 9)
        ii = 9;
    else
        ii = Math.max(i, ii);
    float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null);
    return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}

From source file:Main.java

public static Color shiftHue(Color color) {
    float[] hsl = new float[3];
    Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsl);

    hsl[0] += 0.33f % 1.0f;/* w  w w.  j a va 2  s  .  com*/
    return Color.getHSBColor(hsl[0], hsl[1], hsl[2]);
}

From source file:Main.java

public Main() {
    for (int i = 0; i < MAX; i++) {
        Color color = Color.getHSBColor((float) i / MAX, 1, 1);
        pane.add("Tab " + String.valueOf(i), new TabContent(i, color));
        pane.setBackgroundAt(i, color);//ww w  .ja  v  a2 s  .  c  om
    }
    this.add(pane);
}

From source file:Main.java

public static Color getGradientHsbColor(float ratio, Color minColor, Color maxColor) {
    float[] startHSB = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null);
    float[] endHSB = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null);

    float brightness = (startHSB[2] + endHSB[2]) / 2;
    float saturation = (startHSB[1] + endHSB[1]) / 2;

    float hueMax = 0;
    float hueMin = 0;
    // if (startHSB[0] > endHSB[0]) {
    hueMax = startHSB[0];// w w w  .  java2  s. com
    hueMin = endHSB[0];
    // } else {
    // hueMin = startHSB[0];
    // hueMax = endHSB[0];
    // }

    float hue = ((hueMax - hueMin) * (1.0F - ratio)) + hueMin;

    return Color.getHSBColor(hue, saturation, brightness);
}

From source file:ch.rasc.s4ws.snake.SnakeWebSocketHandler.java

public static String getRandomHexColor() {
    float hue = random.nextFloat();
    // sat between 0.1 and 0.3
    float saturation = (random.nextInt(2000) + 1000) / 10000f;
    float luminance = 0.9f;
    Color color = Color.getHSBColor(hue, saturation, luminance);
    return '#' + Integer.toHexString(color.getRGB() & 0xffffff | 0x1000000).substring(1);
}

From source file:com.gmind7.bakery.websocket.SnakeWebSocketHandler.java

public static String getRandomHexColor() {
    float hue = random.nextFloat();
    // sat between 0.1 and 0.3
    float saturation = (random.nextInt(2000) + 1000) / 10000f;
    float luminance = 0.9f;
    Color color = Color.getHSBColor(hue, saturation, luminance);
    return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
}