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:ColorUtilities.java

public static Color blend(Color c0, Color c1) {
    double totalAlpha = c0.getAlpha() + c1.getAlpha();
    double weight0 = c0.getAlpha() / totalAlpha;
    double weight1 = c1.getAlpha() / totalAlpha;

    double r = weight0 * c0.getRed() + weight1 * c1.getRed();
    double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
    double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
    double a = Math.max(c0.getAlpha(), c1.getAlpha());

    return new Color((int) r, (int) g, (int) b, (int) a);
}

From source file:edu.ku.brc.ui.GradiantButton.java

/**
* Generate the alpha version of this color
* @param color the color in question//  w ww . ja  va  2  s.c  om
* @param alpha the alpha of the new color
* @return Generate the alpha version of this color
*/
protected static Color alphaColor(Color color, int alpha) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}

From source file:org.asqatasun.rules.elementchecker.contrast.helper.ContrastHelper.java

/**
 *
 * @param color/* w w w . j a  va2 s .co m*/
 * @return
 */
public static double getLuminosity(Color color) {
    double luminosity = getComposantValue(color.getRed()) * RED_FACTOR
            + getComposantValue(color.getGreen()) * GREEN_FACTOR
            + getComposantValue(color.getBlue()) * BLUE_FACTOR;

    return luminosity;
}

From source file:Main.java

/**
 * Make a color scaled using a defined factor.
 *
 * @param color/*  w ww . j a  v  a2  s .  c  o  m*/
 *          the color to scale.
 * @param factor
 *          the factor to use.
 * @return the scaled color.
 */
public static Color getScaledColor(Color color, double factor) {
    if (color == null) {
        return null;
    }
    if (factor <= 1) {
        return new Color(Math.max((int) (color.getRed() * factor), 0),
                Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0),
                color.getAlpha());
    }
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    int i = (int) (1.0 / (factor - 1));
    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 / (2 - factor)), 255), Math.min((int) (g / (2 - factor)), 255),
            Math.min((int) (b / (2 - factor)), 255));

}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java

public static int calculateBrightness(final Color color) {
    return (int) Math.sqrt(color.getRed() * color.getRed() * .241d + color.getGreen() * color.getGreen() * .691d
            + color.getBlue() * color.getBlue() * .068d);
}

From source file:Gradient.java

/**
 * Creates an array of Color objects for use as a gradient, using a linear
 * interpolation between the two specified colors.
 * /*from  w ww . ja  v a 2s  . c o m*/
 * @param one
 *            Color used for the bottom of the gradient
 * @param two
 *            Color used for the top of the gradient
 * @param numSteps
 *            The number of steps in the gradient. 250 is a good number.
 */
public static Color[] createGradient(final Color one, final Color two, final int numSteps) {
    int r1 = one.getRed();
    int g1 = one.getGreen();
    int b1 = one.getBlue();
    int a1 = one.getAlpha();

    int r2 = two.getRed();
    int g2 = two.getGreen();
    int b2 = two.getBlue();
    int a2 = two.getAlpha();

    int newR = 0;
    int newG = 0;
    int newB = 0;
    int newA = 0;

    Color[] gradient = new Color[numSteps];
    double iNorm;
    for (int i = 0; i < numSteps; i++) {
        iNorm = i / (double) numSteps; // a normalized [0:1] variable
        newR = (int) (r1 + iNorm * (r2 - r1));
        newG = (int) (g1 + iNorm * (g2 - g1));
        newB = (int) (b1 + iNorm * (b2 - b1));
        newA = (int) (a1 + iNorm * (a2 - a1));
        gradient[i] = new Color(newR, newG, newB, newA);
    }

    return gradient;
}

From source file:com.gargoylesoftware.htmlunit.util.StringUtils.java

/**
 * Formats the specified color.//from  w ww  .ja  va  2s.  co m
 *
 * @param aColor the color to format
 * @return the specified color, formatted
 */
public static String formatColor(final Color aColor) {
    return "rgb(" + aColor.getRed() + ", " + aColor.getGreen() + ", " + aColor.getBlue() + ")";
}

From source file:Util.java

/**
 * Return a string representation of a color
 * // ww  w.ja va2s .co  m
 * @param color
 * @return string representation
 */
public static String colorToString(Color color) {
    if (color == null) {
        return "";
    }

    StringBuffer buf = new StringBuffer();
    buf.append('#');
    buf.append(numberToPaddedHexString(color.getRed(), 2));
    buf.append(numberToPaddedHexString(color.getGreen(), 2));
    buf.append(numberToPaddedHexString(color.getBlue(), 2));

    return buf.toString();
}

From source file:joinery.impl.Display.java

private static void addTrend(final Chart chart, final Series series, final List<Object> xdata) {
    final SimpleRegression model = new SimpleRegression();
    final Iterator<? extends Number> y = series.getYData().iterator();
    for (int x = 0; y.hasNext(); x++) {
        model.addData(x, y.next().doubleValue());
    }/*  w ww.  j a  va  2s.  com*/
    final Color mc = series.getMarkerColor();
    final Color c = new Color(mc.getRed(), mc.getGreen(), mc.getBlue(), 0x60);
    final Series trend = chart.addSeries(series.getName() + " (trend)",
            Arrays.asList(xdata.get(0), xdata.get(xdata.size() - 1)),
            Arrays.asList(model.predict(0), model.predict(xdata.size() - 1)));
    trend.setLineColor(c);
    trend.setMarker(SeriesMarker.NONE);
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractGreenColor(BufferedImage source) {
    //Extracts the Green value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getGreen();
            values[(i * imageWidth) + j] = value;
        }//w  w  w.  j  av a 2  s. co m
    }

    return values;
}