Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

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

Prototype

public int getBlue() 

Source Link

Document

Returns the blue component in the range 0-255 in the default sRGB space.

Usage

From source file:com.technofovea.packbsp.gui2.jung.DependencyVisualizer.java

static Color trans(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue(), 128);

}

From source file:Main.java

/**
 * A utility  to set the attribute on the given node as the
 * String representation of the given color
 *
 * @param node The node//from ww  w.j av  a 2  s  .  c om
 * @param name The attr name
 * @param value The color
 */
public static void setAttribute(Element node, String name, Color value) {
    node.setAttribute(name, "" + value.getRed() + "," + value.getGreen() + "," + value.getBlue());
}

From source file:Main.java

public static Color averageColor(Color c1, Color c2) {
    return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
            (c1.getBlue() + c2.getBlue()) / 2);
}

From source file:ColorUtil.java

public static Color copy(Color c) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}

From source file:Main.java

/**
 * Make the color brighter by the specified factor.
 * <p/>//ww  w.  ja v  a  2  s .  c  o m
 * This code is adapted from java.awt.Color to take in a factor.
 * Therefore, it inherits its quirks. Most importantly,
 * a smaller factor makes the color more bright.
 *
 * @param c      a color
 * @param factor the smaller the factor, the brighter.
 * @return a brighter color
 */
private static Color brighter(Color c, double factor) {
    int r = c.getRed();
    int g = c.getGreen();
    int b = c.getBlue();

    /* From 2D group:
     * 1. black.brighter() should return grey
     * 2. applying brighter to blue will always return blue, brighter
     * 3. non pure color (non zero rgb) will eventually return white
     */
    int i = (int) (1.0 / (1.0 - factor));
    if (r == 0 && g == 0 && b == 0) {
        return new Color(i, i, i);
    }
    if (r > 0 && r < i)
        r = i;
    if (g > 0 && g < i)
        g = i;
    if (b > 0 && b < i)
        b = i;

    return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255),
            Math.min((int) (b / factor), 255));
}

From source file:Main.java

/**
 * Returns color copy./*from   w  ww. ja va  2 s .co m*/
 *
 * @param color
 *            color to copy
 * @return color copy
 */
public static Color copy(final Color color) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}

From source file:ColorUtil.java

public static Color setAlpha(Color c, int alpha) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
}

From source file:Main.java

/**
 * attach (append to child) RGB to the element, in the format <red>12</red> etc
 * @param rgb//ww  w .j  av  a 2s. co  m
 * @param elem
 * @param doc
 */
public static void attachRGB(Color rgb, Element elem, Document doc) {
    int r = rgb.getRed();
    int g = rgb.getGreen();
    int b = rgb.getBlue();

    //create element
    Element red = doc.createElement(TAG_NAME_RED);
    Element green = doc.createElement(TAG_NAME_GREEN);
    Element blue = doc.createElement(TAG_NAME_BLUE);

    //fill the content
    red.appendChild(doc.createTextNode(Integer.toString(r)));
    green.appendChild(doc.createTextNode(Integer.toString(g)));
    blue.appendChild(doc.createTextNode(Integer.toString(b)));

    //structure the content
    elem.appendChild(red);
    elem.appendChild(green);
    elem.appendChild(blue);
}

From source file:Utils.java

/**
 * Derives a color by adding the specified offsets to the base color's 
 * hue, saturation, and brightness values.   The resulting hue, saturation,
 * and brightness values will be contrained to be between 0 and 1.
 * @param base the color to which the HSV offsets will be added
 * @param dH the offset for hue//www  .  j  av a 2  s  .c  om
 * @param dS the offset for saturation
 * @param dB the offset for brightness
 * @return Color with modified HSV values
 */
public static Color deriveColorHSB(Color base, float dH, float dS, float dB) {
    float hsb[] = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null);

    hsb[0] += dH;
    hsb[1] += dS;
    hsb[2] += dB;
    return Color.getHSBColor(hsb[0] < 0 ? 0 : (hsb[0] > 1 ? 1 : hsb[0]),
            hsb[1] < 0 ? 0 : (hsb[1] > 1 ? 1 : hsb[1]), hsb[2] < 0 ? 0 : (hsb[2] > 1 ? 1 : hsb[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];/*w  w  w.  ja v  a  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);
}