Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

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

Usage

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

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 . j  a  v  a2  s. co  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:Main.java

/**
 * Creates a new <code>Color</code> that is a brighter version of this
 * <code>Color</code>. This method is the same implementation
 * java.awt.Color#brighter is usind except it has a configurable factor.
 * The java.awt.Color default facotr is 0.7
 * @return     a new <code>Color</code> object that is  
 *                 a brighter version of this <code>Color</code>.
 * @see        java.awt.Color#darker/*from  www. ja  va2s  .c  om*/
 */
public static Color brighterColor(Color color, double factor) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.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: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/*  w w w.  j  av  a2  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:ColorUtils.java

/**
 * Lightens a color by a given amount/*  w  w w  .  j a v a  2  s . c  o m*/
 * 
 * @param color The color to lighten
 * @param amount The amount to lighten the color. 0 will leave the color unchanged; 1 will make
 *        the color completely white
 * @return The bleached color
 */
public static Color bleach(Color color, float amount) {
    int red = (int) ((color.getRed() * (1 - amount) / 255 + amount) * 255);
    int green = (int) ((color.getGreen() * (1 - amount) / 255 + amount) * 255);
    int blue = (int) ((color.getBlue() * (1 - amount) / 255 + amount) * 255);
    return new Color(red, green, blue);
}

From source file:Main.java

public static Color neighbour(Color c1, Color c2, double f) {
    return new Color(c1.getRed() + (int) ((c2.getRed() - c1.getRed()) * f),
            c1.getGreen() + (int) ((c2.getGreen() - c1.getGreen()) * f),
            c1.getBlue() + (int) ((c2.getBlue() - c1.getBlue()) * f),
            c1.getAlpha() + (int) ((c2.getAlpha() - c1.getAlpha()) * f));
}

From source file:Main.java

/**
 * Create a lighter color using a factor.
 *
 * @param color// w ww .  j  a v a2 s .c  o  m
 * @param factor
 * @return lighter color
 */
public static Color lighter(final Color color, float factor) {
    return new Color(Math.max((int) (color.getRed() / factor), 0),
            Math.max((int) (color.getGreen() / factor), 0), Math.max((int) (color.getBlue() / factor), 0));
}

From source file:Main.java

/**
 * Create a darker color using a factor.
 *
 * @param color/*from  w  w  w.  j  ava  2  s. co  m*/
 * @param factor
 * @return darker color
 */
public static Color darker(final Color color, float factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:Main.java

/**
 * Creates a new <code>Color</code> that is a darker version of this
 * <code>Color</code>. This method is the same implementation
 * java.awt.Color#darker is usind except it has a configurable factor.
 * The java.awt.Color default facotr is 0.7
 * @return  a new <code>Color</code> object that is 
 *                    a darker version of this <code>Color</code>.
 * @see        java.awt.Color#brighter//from w  w  w  .  j a  v a 2 s .  co  m
 */
public static Color darkerColor(Color color, double factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:proteinHypernetworkVisualization.implementation.jung.visualization.DefaultGraphStyle.java

public static Color makeTransparent(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue(), 150);
}