public final class RgbaColor extends Object
Constructor and Description |
---|
RgbaColor()
Creates an RgbaColor as rgba(0,0,0,1)
|
RgbaColor(int r,
int g,
int b)
Creates an RgbaColor with alpha=1
|
RgbaColor(int r,
int g,
int b,
float a)
Creates an RgbaColor
|
Modifier and Type | Method and Description |
---|---|
float |
a()
Returns the value of the alpha component [0-1]
|
RgbaColor |
adjustHue(float degrees)
Returns a new color that has the hue adjusted by the specified
amount.
|
float |
alpha()
Returns the value of the alpha component [0-1]
|
protected static float |
alphaCheck(float alpha) |
int |
b()
Returns the value of the blue component (0-255)
|
int |
blue()
Returns the value of the blue component [0-255]
|
RgbaColor |
complement()
Returns a new color that is the complement of this color.
|
float[] |
convertToHsl()
Returns a triple of hue [0-360), saturation [0-100], and
lightness [0-100].
|
RgbaColor |
darken(float amount)
Returns a new color that has the lightness adjusted by the
negative of the specified amount.
|
RgbaColor |
darkenOrLighten(float darken,
float lighten)
First attempt to darken the color and if that overflows the
lightness component, lighten the color.
|
RgbaColor |
desaturate(float amount)
Returns a new color that has the saturation adjusted by the
negative of the specified amount.
|
RgbaColor |
desaturateOrSaturate(float desaturate,
float saturate)
First attempt to desaturate the color and if that overflows the
saturation component, saturate the color.
|
boolean |
equals(Object other) |
static RgbaColor |
from(String color)
Parses an RgbaColor from a hexadecimal, rgb, rgba, hsl, or hsla
value.
|
static RgbaColor |
fromHex(String hex)
Parses an RgbaColor from a hexadecimal value.
|
static RgbaColor |
fromHsl(float[] hsl)
Convenience to get back to RGB from HSL array returned by
toHSL.
|
static RgbaColor |
fromHsl(float H,
float S,
float L)
Creates a new RgbaColor from the specified HSL components.
|
static RgbaColor |
fromHsl(String hsl)
Parses an RgbaColor from a CSS3 HSL value, e.g.
|
static RgbaColor |
fromHsla(String hsl)
Parses an RgbaColor from a CSS3 HSLA value, e.g.
|
static RgbaColor |
fromRgb(String rgb)
Parses an RgbaColor from an rgb value.
|
static RgbaColor |
fromRgba(String rgba)
Parses an RgbaColor from an rgba value.
|
int |
g()
Returns the value of the green component (0-255)
|
RgbaColor[] |
getPaletteVaryLightness(int count) |
protected static float[] |
getSpreadInRange(float member,
int count,
int max,
int offset)
Returns a spread of integers in a range [0,max) that includes
count.
|
RgbaColor |
grayscale()
Returns a new color that is the grayscale equivalent of this
color (with saturation = 0).
|
int |
green()
Returns the value of the green component [0-255]
|
float |
h()
Returns the value of the hue component of this color as HSL
[0-360)
|
int |
hashCode() |
float |
hue()
Returns the value of the hue component of this color as HSL
[0-360)
|
protected static float |
hueCheck(float hue) |
RgbaColor |
inverse()
Returns a new color that is the inverse of this color where
each rgb component is subtracted from 255.
|
float |
l()
Returns the value of the lightness component of this color as
HSL [0-100]
|
RgbaColor |
lighten(float amount)
Returns a new color that has the lightness adjusted by the
specified amount.
|
RgbaColor |
lightenOrDarken(float lighten,
float darken)
First attempt to lighten the color and if that overflows the
lightness component, darken the color.
|
float |
lightness()
Returns the value of the lightness component of this color as
HSL [0-100]
|
RgbaColor |
opacify(float amount)
Returns a new color that has the alpha adjusted by the
specified amount.
|
int |
r()
Returns the value of the red component (0-255)
|
int |
red()
Returns the value of the red component [0-255]
|
protected static int |
rgbCheck(int rgb) |
float |
s()
Returns the value of the saturation component of this color as
HSL [0-100]
|
RgbaColor |
saturate(float amount)
Returns a new color that has the saturation adjusted by the
specified amount.
|
RgbaColor |
saturateOrDesaturate(float saturate,
float desaturate)
First attempt to saturate the color and if that overflows the
saturation component, desaturate the color.
|
float |
saturation()
Returns the value of the saturation component of this color as
HSL [0-100]
|
protected static float |
slCheck(float sl) |
String |
toHex()
Returns the color in hexadecimal format (#rrggbb)
|
String |
toHsl()
Returns the CSS3 HSL representation, e.g.
|
String |
toHsla()
Returns the CSS3 HSLA representation, e.g.
|
String |
toRgb()
Returns the color in rgb format, e.g.
|
String |
toRgba()
Returns the color in rgba format, e.g.
|
String |
toString() |
RgbaColor |
transparentize(float amount)
Returns a new color that has the alpha adjusted by the
specified amount.
|
RgbaColor |
withAlpha(float alpha)
Returns a new RgbaColor with the alpha component set to the
specified value.
|
RgbaColor |
withBlue(int blue)
Returns a new RgbaColor with the blue component set to the
specified value.
|
RgbaColor |
withGreen(int green)
Returns a new RgbaColor with the green component set to the
specified value.
|
RgbaColor |
withHue(float hue)
Returns a new RgbaColor with the hue component set to the
specified value.
|
RgbaColor |
withLightness(float lightness)
Returns a new RgbaColor with the lightness component set to the
specified value.
|
RgbaColor |
withRed(int red)
Returns a new RgbaColor with the red component set to the
specified value.
|
RgbaColor |
withSaturation(float saturation)
Returns a new RgbaColor with the saturation component set to
the specified value.
|
public RgbaColor()
public RgbaColor(int r, int g, int b)
r
- the red component [0-255]g
- the green component [0-255]b
- the blue component [0-255]public RgbaColor(int r, int g, int b, float a)
r
- the red component [0-255]g
- the green component [0-255]b
- the blue component [0-255]a
- the alpha component [0-1]public static RgbaColor from(String color)
public static RgbaColor fromHex(String hex)
public static RgbaColor fromRgb(String rgb)
public static RgbaColor fromRgba(String rgba)
public static RgbaColor fromHsl(String hsl)
public static RgbaColor fromHsla(String hsl)
public static RgbaColor fromHsl(float[] hsl)
public int red()
public int green()
public int blue()
public float hue()
public float saturation()
public float lightness()
public float alpha()
public int r()
public int g()
public int b()
public float h()
public float s()
public float l()
public float a()
public RgbaColor withRed(int red)
public RgbaColor withBlue(int blue)
public RgbaColor withGreen(int green)
public RgbaColor withAlpha(float alpha)
public RgbaColor withHue(float hue)
public RgbaColor withSaturation(float saturation)
public RgbaColor withLightness(float lightness)
public RgbaColor complement()
public RgbaColor grayscale()
public RgbaColor inverse()
public RgbaColor adjustHue(float degrees)
public RgbaColor opacify(float amount)
public RgbaColor transparentize(float amount)
public RgbaColor lighten(float amount)
public RgbaColor darken(float amount)
public RgbaColor saturate(float amount)
public RgbaColor desaturate(float amount)
public RgbaColor[] getPaletteVaryLightness(int count)
protected static final float[] getSpreadInRange(float member, int count, int max, int offset)
public RgbaColor lightenOrDarken(float lighten, float darken)
public RgbaColor darkenOrLighten(float darken, float lighten)
public RgbaColor saturateOrDesaturate(float saturate, float desaturate)
public RgbaColor desaturateOrSaturate(float desaturate, float saturate)
public float[] convertToHsl()
Implementation based on wikipedia
public static RgbaColor fromHsl(float H, float S, float L)
H
- Hue [0,360)S
- Saturation [0,100]L
- Lightness [0,100]public String toHex()
public String toRgb()
public String toRgba()
public String toHsl()
public String toHsla()
protected static int rgbCheck(int rgb)
protected static float hueCheck(float hue)
protected static float slCheck(float sl)
protected static float alphaCheck(float alpha)
Copyright © 2015. All Rights Reserved.