Java Color Darker deriveColor(Color orig, int darker)

Here you can find the source of deriveColor(Color orig, int darker)

Description

Derives a color from another color by linearly shifting its blue, green, and blue values.

License

BSD License

Parameter

Parameter Description
orig The original color.
darker The amount by which to decrease its r, g, and b values. Note that you can use negative values for making a color component "brighter." If this makes any of the three values less than zero, zero is used for that component value; similarly, if it makes any value greater than 255, 255 is used for that component's value.

Declaration

public static final Color deriveColor(Color orig, int darker) 

Method Source Code

//package com.java2s;
/*//from   www  . ja  v  a 2s .co m
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.ui classes.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */

import java.awt.Color;

public class Main {
    /**
     * Derives a color from another color by linearly shifting its blue, green,
     * and blue values.
     *
     * @param orig The original color.
     * @param darker The amount by which to decrease its r, g, and b values.
     *        Note that you can use negative values for making a color
     *        component "brighter."  If this makes any of the three values
     *        less than zero, zero is used for that component value; similarly,
     *        if it makes any value greater than 255, 255 is used for that
     *        component's value.
     */
    public static final Color deriveColor(Color orig, int darker) {

        int red = orig.getRed() - darker;
        int green = orig.getGreen() - darker;
        int blue = orig.getBlue() - darker;

        if (red < 0)
            red = 0;
        else if (red > 255)
            red = 255;
        if (green < 0)
            green = 0;
        else if (green > 255)
            green = 255;
        if (blue < 0)
            blue = 0;
        else if (blue > 255)
            blue = 255;

        return new Color(red, green, blue);

    }
}

Related

  1. darker(int channel, int intensity)
  2. darkerColor(Color c)
  3. darkerColor(Color c, double amount)
  4. darkerColor(Color color, double factor)
  5. darkerColor(String hexValue)
  6. draw3DFrame(Graphics g, Rectangle rect, Color colorBackground, Color colorDark, Color colorLight)
  7. getDarkColor()
  8. getDarkColors(Color[] colors, double fraction)
  9. getDarker(Color c)