Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

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

Usage

From source file:Main.java

public static Color darken(Color c, int r, int g, int b) {
    int or = c.getRed(), og = c.getGreen(), ob = c.getBlue();
    or -= r;/*  www  .  ja  va 2s  .c  om*/
    og -= g;
    ob -= b;
    or = or < 0 ? 0 : or;
    or = or > 255 ? 255 : or;
    og = og < 0 ? 0 : og;
    og = og > 255 ? 255 : og;
    ob = ob < 0 ? 0 : ob;
    ob = ob > 255 ? 255 : ob;
    return new Color(or, og, ob);
}

From source file:Main.java

/**
 * @param color//  w w w  .j a v a  2 s  .  co  m
 * @param factor
 * @return a new color, darker than the one passed as argument by a percentage factor
 *
 * <br>author Cyril Gambis  - [Mar 17, 2005]
 */
public static Color darker(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: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:GuiUtil.java

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

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// w  w w  .j av  a 2 s  .  co m
 * @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:HTML.java

/**
 * Utility method to format a color to HTML RGB color format (e.g. #FF0000 for Color.red).
 * @param color The color./*  ww  w . j  a  v a  2 s  . c  o  m*/
 * @return the HTML RGB color string.
 */
public static final String format(Color c) {
    String r = (c.getRed() < 16) ? "0" + Integer.toHexString(c.getRed()) : Integer.toHexString(c.getRed());
    String g = (c.getGreen() < 16) ? "0" + Integer.toHexString(c.getGreen())
            : Integer.toHexString(c.getGreen());
    String b = (c.getBlue() < 16) ? "0" + Integer.toHexString(c.getBlue()) : Integer.toHexString(c.getBlue());
    return "#" + r + g + b;
}

From source file:Main.java

/**
 * Make the color brighter by the specified factor.
 * <p/>//  w  w w .j  av a2 s . c  om
 * 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:ColorUtil.java

public static boolean isDark(Color c) {
    return c.getRed() + c.getGreen() + c.getBlue() < 3 * 180;
}

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 ava  2s. c  o m*/
    return Color.getHSBColor(hsl[0], hsl[1], hsl[2]);
}

From source file:Main.java

/**
 * Create a lighter color using a factor.
 *
 * @param color/*from   w  ww.ja  v a 2 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));
}