Package toxi.color
Class TColor
java.lang.Object
toxi.color.TColor
- All Implemented Interfaces:
ReadonlyTColor
Floating point color class with implicit RGB, HSV, CMYK access modes,
conversion and color theory utils. Based on the Colors library
for NodeBox
-
Field Summary
FieldsModifier and TypeFieldDescriptionfloatstatic final ReadonlyTColorstatic floatMaximum rgb component value for a color to be classified as black.static final ReadonlyTColorstatic final ReadonlyTColorstatic final ReadonlyTColorstatic floatMaximum saturations value for a color to be classified as greystatic final ReadonlyTColorstatic final ReadonlyTColorstatic final ReadonlyTColorstatic floatMinimum rgb component value for a color to be classified as white.static final ReadonlyTColor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadjustConstrast(float amount) Changes the brightness of the color by the given amount in the direction towards either the black or white point (depending on if current brightness >= 50%)adjustHSV(float h, float s, float v) Adds the given HSV values as offsets to the current color.adjustRGB(float r, float g, float b) Adds the given RGB values as offsets to the current color.floatalpha()analog(float theta, float delta) Rotates this color by a random amount (not exceeding the one specified) and creates variations in saturation and brightness based on the 2nd parameter.analog(int angle, float delta) floatblack()blend(ReadonlyTColor c, float t) Blends the color with the given one by the stated amountfloatblue()floatstatic final float[]cmykToRGB(float c, float m, float y, float k) Converts CMYK floats into an RGB array.static final float[]cmykToRGB(float c, float m, float y, float k, float[] rgb) Converts CMYK floats into the given RGB array.copy()floatcyan()darken(float step) Reduces the color's brightness by the given amount (e.g 0.1 = 10% darker).desaturate(float step) Reduced the color's saturation by the given amount.floatCalculates the CMYK distance to the given color.floatCalculates the HSV distance to the given color.floatCalculates the RGB distance to the given color.booleangetAnalog(float theta, float delta) getAnalog(int angle, float delta) getBlended(ReadonlyTColor c, float t) getClosestHue(boolean primaryOnly) floatgetComponentValue(AccessCriteria criteria) getDarkened(float step) getDesaturated(float step) getLightened(float step) getRotatedRYB(float theta) getRotatedRYB(int angle) getSaturated(float step) floatgreen()inthashCode()static final float[]Converts hex string into a RGB array.static final float[]static final float[]hsvToRGB(float h, float s, float v) Converts HSV values into RGB array.static final float[]hsvToRGB(float h, float s, float v, float[] rgb) floathue()invert()Inverts the color.booleanisBlack()booleanisGrey()booleanbooleanisWhite()static final float[]labToRGB(float l, float a, float b) static final float[]labToRGB(float l, float a, float b, float[] rgb) Converts CIE Lab to RGB components.lighten(float step) Lightens the color by stated amount.floatComputes the color's luminance using this formula: lum=0.299*red + 0.587*green + 0.114 *bluefloatmagenta()static final TColornewARGB(int argb) Factory method.static final TColornewCMYK(float c, float m, float y, float k) Factory method.static final TColornewCMYKA(float c, float m, float y, float k, float a) Factory method.static final TColornewGray(float gray) Factory method.static final TColornewGrayAlpha(float gray, float alpha) Factory method.static final TColorFactory method.static final TColornewHSV(float h, float s, float v) Factory method.static ReadonlyTColorstatic final TColornewHSVA(float h, float s, float v, float a) static final TColorFactory method.static final TColornewRGB(float r, float g, float b) Factory method.static final TColornewRGBA(float r, float g, float b, float a) floatred()static final float[]rgbToCMYK(float r, float g, float b) Converts the RGB values into a CMYK array.static final float[]rgbToCMYK(float r, float g, float b, float[] cmyk) static final StringrgbToHex(float r, float g, float b) Formats the RGB float values into hex integers.static final float[]rgbToHSV(float r, float g, float b) Converts the RGB values into an HSV array.static final float[]rgbToHSV(float r, float g, float b, float[] hsv) rotateRYB(float theta) rotateRYB(int theta) Rotates the color by x degrees along the RYB color wheelsaturate(float step) Adds the given value to the current saturation component.floatsetAlpha(float alpha) setARGB(int argb) Sets all color components to new values interpreted from the given packed ARGB 32bit color value.setBlack(float val) setBlue(float blue) setBrightness(float brightness) setCMYK(float[] newCMYK) setCMYK(float c, float m, float y, float k) setComponent(AccessCriteria criteria, float val) Sets a color component by name.setCyan(float val) setGreen(float green) setHSV(float[] newHSV) setHSV(float h, float s, float v) setHue(float hue) setMagenta(float val) setRed(float red) setRGB(float[] newRGB) setRGB(float r, float g, float b) setSaturation(float saturation) setYellow(float val) inttoARGB()Converts the color into a packed ARGB int.float[]toCMYKAArray(float[] cmyka) Copies the current CMYKA values into the given array (or constucts a new one with these values).toHex()Converts the color into a 6 digit hex string.float[]toHSVAArray(float[] hsva) float[]toRGBAArray(float[] rgba) Copies the current RGBA value into the given array (or constucts a new one with these values).float[]toRGBAArray(float[] rgba, int offset) Copies the current RGBA value into the given array starting the given offset.toString()floatyellow()
-
Field Details
-
BLACK_POINT
public static float BLACK_POINTMaximum rgb component value for a color to be classified as black.- See Also:
-
WHITE_POINT
public static float WHITE_POINTMinimum rgb component value for a color to be classified as white.- See Also:
-
GREY_THRESHOLD
public static float GREY_THRESHOLDMaximum saturations value for a color to be classified as grey- See Also:
-
RED
-
GREEN
-
BLUE
-
CYAN
-
MAGENTA
-
YELLOW
-
BLACK
-
WHITE
-
alpha
public float alpha
-
-
Constructor Details
-
TColor
Creates a deep copy of the given color.- Parameters:
c-
-
-
Method Details
-
cmykToRGB
public static final float[] cmykToRGB(float c, float m, float y, float k) Converts CMYK floats into an RGB array.- Parameters:
c-m-y-k-- Returns:
- rgb array
-
cmykToRGB
public static final float[] cmykToRGB(float c, float m, float y, float k, float[] rgb) Converts CMYK floats into the given RGB array.- Parameters:
c-m-y-k-rgb-- Returns:
- rgb array
-
hexToRGB
Converts hex string into a RGB array.- Parameters:
hexRGB-- Returns:
- rgb array
-
hexToRGB
-
hsvToRGB
public static final float[] hsvToRGB(float h, float s, float v) Converts HSV values into RGB array.- Parameters:
h-s-v-- Returns:
- rgb array
-
hsvToRGB
public static final float[] hsvToRGB(float h, float s, float v, float[] rgb) -
labToRGB
public static final float[] labToRGB(float l, float a, float b) -
labToRGB
public static final float[] labToRGB(float l, float a, float b, float[] rgb) Converts CIE Lab to RGB components. First we have to convert to XYZ color space. Conversion involves using a white point, in this case D65 which represents daylight illumination. Algorithm adopted from: http://www.easyrgb.com/math.php- Parameters:
l-a-b-rgb-- Returns:
- rgb array
-
newARGB
Factory method. Creates new color from ARGB int.- Parameters:
argb-- Returns:
- new color
-
newCMYK
Factory method. Creates new color from CMYK values.- Parameters:
c-m-y-k-- Returns:
- new color
-
newCMYKA
Factory method. Creates new color from CMYK + alpha values.- Parameters:
c-m-y-k-a-- Returns:
- new color
-
newGray
Factory method. Creates a new shade of gray with alpha set to 100%.- Parameters:
gray-- Returns:
- new color.
-
newGrayAlpha
Factory method. Creates a new shade of gray + alpha.- Parameters:
gray-alpha-- Returns:
- new color.
-
newHex
Factory method. Creates a new color from hex string. Supports standard 6 digit RGB colors or 8 digit ARGB.- Parameters:
hexRGB-- Returns:
- new color
-
newHSV
Factory method. New color from hsv values.- Parameters:
h-s-v-- Returns:
- new color
-
newHSV
-
newHSVA
-
newRandom
Factory method. Creates new random color. Alpha is always 1.0.- Returns:
- random color
-
newRGB
Factory method. Creates new color from RGB values. Alpha is set to 1.0.- Parameters:
r-g-b-- Returns:
- new color
-
newRGBA
-
rgbToCMYK
public static final float[] rgbToCMYK(float r, float g, float b) Converts the RGB values into a CMYK array.- Parameters:
r-g-b-- Returns:
- cmyk array
-
rgbToCMYK
public static final float[] rgbToCMYK(float r, float g, float b, float[] cmyk) -
rgbToHex
Formats the RGB float values into hex integers.- Parameters:
r-g-b-- Returns:
- hex string
-
rgbToHSV
public static final float[] rgbToHSV(float r, float g, float b) Converts the RGB values into an HSV array.- Parameters:
r-g-b-- Returns:
- hsv array
-
rgbToHSV
public static final float[] rgbToHSV(float r, float g, float b, float[] hsv) -
add
-
addSelf
-
adjustConstrast
Changes the brightness of the color by the given amount in the direction towards either the black or white point (depending on if current brightness >= 50%)- Parameters:
amount-- Returns:
- itself
-
adjustHSV
Adds the given HSV values as offsets to the current color. Hue will automatically wrap.- Parameters:
h-s-v-- Returns:
- itself
-
adjustRGB
Adds the given RGB values as offsets to the current color. TColor will clip at black or white.- Parameters:
r-g-b-- Returns:
- itself
-
alpha
public float alpha()- Specified by:
alphain interfaceReadonlyTColor- Returns:
- the color's alpha component
-
analog
Rotates this color by a random amount (not exceeding the one specified) and creates variations in saturation and brightness based on the 2nd parameter.- Parameters:
theta- max. rotation angle (in radians)delta- max. sat/bri variance- Returns:
- itself
-
analog
-
black
public float black()- Specified by:
blackin interfaceReadonlyTColor- Returns:
- the color's black component
-
blend
Blends the color with the given one by the stated amount- Parameters:
c- target colort- interpolation factor- Returns:
- itself
-
blue
public float blue()- Specified by:
bluein interfaceReadonlyTColor- Returns:
- the color's blue component
-
brightness
public float brightness()- Specified by:
brightnessin interfaceReadonlyTColor- Returns:
- color HSV brightness (not luminance!)
-
complement
- Returns:
- ifself, as complementary color
-
copy
- Specified by:
copyin interfaceReadonlyTColor- Returns:
- a mutable copy of the current color
-
cyan
public float cyan()- Specified by:
cyanin interfaceReadonlyTColor- Returns:
- the color's cyan component
-
darken
Reduces the color's brightness by the given amount (e.g 0.1 = 10% darker).- Parameters:
step-- Returns:
- itself
-
desaturate
Reduced the color's saturation by the given amount.- Parameters:
step-- Returns:
- itself
-
differenceTo
-
distanceToCMYK
Description copied from interface:ReadonlyTColorCalculates the CMYK distance to the given color.- Specified by:
distanceToCMYKin interfaceReadonlyTColor- Parameters:
c- target color- Returns:
- distance
-
distanceToHSV
Description copied from interface:ReadonlyTColorCalculates the HSV distance to the given color.- Specified by:
distanceToHSVin interfaceReadonlyTColor- Parameters:
c- target color- Returns:
- distance
-
distanceToRGB
Description copied from interface:ReadonlyTColorCalculates the RGB distance to the given color.- Specified by:
distanceToRGBin interfaceReadonlyTColor- Parameters:
c- target color- Returns:
- distance
-
equals
-
getAnalog
- Specified by:
getAnalogin interfaceReadonlyTColor
-
getAnalog
- Specified by:
getAnalogin interfaceReadonlyTColor
-
getBlended
- Specified by:
getBlendedin interfaceReadonlyTColor
-
getClosestHue
- Specified by:
getClosestHuein interfaceReadonlyTColor- Returns:
- an instance of the closest named hue to this color.
-
getClosestHue
- Specified by:
getClosestHuein interfaceReadonlyTColor- Parameters:
primaryOnly- if true, only primary color hues are considered- Returns:
- an instance of the closest named (primary) hue to this color.
-
getComplement
- Specified by:
getComplementin interfaceReadonlyTColor
-
getComponentValue
- Specified by:
getComponentValuein interfaceReadonlyTColor
-
getDarkened
- Specified by:
getDarkenedin interfaceReadonlyTColor- Returns:
- a darkened copy
-
getDesaturated
- Specified by:
getDesaturatedin interfaceReadonlyTColor- Returns:
- a desaturated copy
-
getDifferenceTo
-
getInverted
- Specified by:
getInvertedin interfaceReadonlyTColor- Returns:
- an inverted copy
-
getLightened
- Specified by:
getLightenedin interfaceReadonlyTColor- Returns:
- a lightened copy
-
getRotatedRYB
- Specified by:
getRotatedRYBin interfaceReadonlyTColor- Parameters:
theta- rotation angle in radians- Returns:
- a RYB rotated copy
-
getRotatedRYB
- Specified by:
getRotatedRYBin interfaceReadonlyTColor- Parameters:
angle- rotation angle in degrees- Returns:
- a RYB rotated copy
-
getSaturated
- Specified by:
getSaturatedin interfaceReadonlyTColor- Returns:
- a saturated copy
-
green
public float green()- Specified by:
greenin interfaceReadonlyTColor- Returns:
- the color's green component
-
hashCode
public int hashCode() -
hue
public float hue()- Specified by:
huein interfaceReadonlyTColor- Returns:
- the color's hue
-
invert
Inverts the color.- Returns:
- itself
-
isBlack
public boolean isBlack()- Specified by:
isBlackin interfaceReadonlyTColor- Returns:
- true, if all rgb component values are equal and less than
BLACK_POINT
-
isGrey
public boolean isGrey()- Specified by:
isGreyin interfaceReadonlyTColor- Returns:
- true, if the saturation component value is less than
GREY_THRESHOLD
-
isPrimary
public boolean isPrimary()- Specified by:
isPrimaryin interfaceReadonlyTColor- Returns:
- true, if this colors hue is matching one of the 7 defined primary hues.
-
isWhite
public boolean isWhite()- Specified by:
isWhitein interfaceReadonlyTColor- Returns:
- true, if all rgb component values are equal and greater than
WHITE_POINT
-
lighten
Lightens the color by stated amount.- Parameters:
step- lighten amount- Returns:
- itself
-
luminance
public float luminance()Description copied from interface:ReadonlyTColorComputes the color's luminance using this formula: lum=0.299*red + 0.587*green + 0.114 *blue- Specified by:
luminancein interfaceReadonlyTColor- Returns:
- luminance
-
magenta
public float magenta()- Specified by:
magentain interfaceReadonlyTColor- Returns:
- the color's magenta component
-
red
public float red()- Specified by:
redin interfaceReadonlyTColor- Returns:
- the color's red component
-
rotateRYB
-
rotateRYB
Rotates the color by x degrees along the RYB color wheel- Parameters:
theta-- Returns:
- itself
-
saturate
Adds the given value to the current saturation component.- Parameters:
step-- Returns:
- itself
-
saturation
public float saturation()- Specified by:
saturationin interfaceReadonlyTColor- Returns:
- the color's saturation
-
setAlpha
-
setARGB
Sets all color components to new values interpreted from the given packed ARGB 32bit color value.- Parameters:
argb-- Returns:
- itself
-
setBlack
-
setBlue
-
setBrightness
-
setCMYK
-
setCMYK
-
setComponent
Sets a color component by name.- Parameters:
criteria-val-- Returns:
- itself
- See Also:
-
setCyan
-
setGreen
-
setHSV
-
setHSV
-
setHue
-
setMagenta
-
setRed
-
setRGB
-
setRGB
-
setSaturation
-
setYellow
-
sub
-
subSelf
-
toARGB
public int toARGB()Description copied from interface:ReadonlyTColorConverts the color into a packed ARGB int.- Specified by:
toARGBin interfaceReadonlyTColor- Returns:
- color as int
-
toCMYKAArray
public float[] toCMYKAArray(float[] cmyka) Description copied from interface:ReadonlyTColorCopies the current CMYKA values into the given array (or constucts a new one with these values).- Specified by:
toCMYKAArrayin interfaceReadonlyTColor- Parameters:
cmyka- result array (or null)- Returns:
- array in this order: c,m,y,k,a
-
toHex
Converts the color into a 6 digit hex string.- Returns:
- color as hex
-
toHSVAArray
public float[] toHSVAArray(float[] hsva) - Specified by:
toHSVAArrayin interfaceReadonlyTColor- Parameters:
hsva- result array (or null)- Returns:
- Copies the the current HSV values into the given array (or constucts a new one with these values).
-
toRGBAArray
public float[] toRGBAArray(float[] rgba) Description copied from interface:ReadonlyTColorCopies the current RGBA value into the given array (or constucts a new one with these values).- Specified by:
toRGBAArrayin interfaceReadonlyTColor- Parameters:
rgba- result array (or null)- Returns:
- array in this order: r,g,b,a (OpenGL format)
-
toRGBAArray
public float[] toRGBAArray(float[] rgba, int offset) Description copied from interface:ReadonlyTColorCopies the current RGBA value into the given array starting the given offset. If the array is null, the method constucts a new one with these values and the offset value is ignored (set to zero).- Specified by:
toRGBAArrayin interfaceReadonlyTColor- Returns:
- float array
-
toString
-
yellow
public float yellow()- Specified by:
yellowin interfaceReadonlyTColor- Returns:
- the color's yellow component
-