Example usage for java.awt Color RGBtoHSB

List of usage examples for java.awt Color RGBtoHSB

Introduction

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

Prototype

public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) 

Source Link

Document

Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

Usage

From source file:Main.java

public static void main() {
    int red = 23;
    int green = 66;
    int blue = 99;

    float[] hsb = Color.RGBtoHSB(red, green, blue, null);
    float hue = hsb[0];
    float saturation = hsb[1];
    float brightness = hsb[2];

}

From source file:Main.java

public static void main() {
    int red = 23;
    int green = 66;
    int blue = 99;

    float[] hsb = Color.RGBtoHSB(red, green, blue, null);
    System.out.println(Arrays.toString(hsb));

}

From source file:Util.java

/**
 * Returns n-dimensional array of colors for given nx3 integer array of RGB values. 
 */// w  w  w. ja  va2  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  ava 2  s  . c  o m*/
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  ww w. j  av  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.
 *///  ww w  .j av a  2 s.c o  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  ww . ja v a  2s.  co m
    return Color.getHSBColor(hsl[0], hsl[1], hsl[2]);
}

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];/*from  w w  w  .  java  2 s .  c o  m*/
    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:com.whizzosoftware.hobson.lifx.api.message.HSBK.java

public HSBK(int r, int g, int b) {
    float[] hsb = Color.RGBtoHSB(r, g, b, null);
    this.hue = (int) ((Math.min(hsb[0], 1.0)) * 65535);
    this.saturation = (int) ((Math.min(hsb[1], 1.0)) * 65535);
    this.brightness = (int) ((Math.min(hsb[2], 1.0)) * 65535);
    this.kelvin = DEFAULT_KELVIN;
}

From source file:ColorSchemaGenerator.java

/**
 * Create the schema color./* ww w. j a  va 2  s .c  om*/
 * 
 * @param base
 * @param i (a color between 0 and 3)
 * @param schemaName
 * @return
 */
public static Color createColor(Color base, int i, String schemaName) {

    i = Math.abs(i %= 3);
    if (schemaName == null)
        schemaName = SCHEMA_SOFT;
    float[] schema = schemas.get(schemaName);

    float[] components = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null);

    components[1] = (schema[i * 2] < 0) ? -schema[i * 2] * components[1] : schema[i * 2];
    if (components[1] > 1)
        components[1] = 1.0f;
    if (components[1] < 0)
        components[1] = 0;

    components[2] = (schema[i * 2 + 1] < 0) ? -schema[i * 2 + 1] * components[2] : schema[i * 2 + 1];
    if (components[2] > 1)
        components[2] = 1.0f;
    if (components[2] < 0)
        components[2] = 0;

    return new Color(Color.HSBtoRGB(components[0], components[1], components[2]));
}