pex- colorColor utilities for the pex library
Color
copy(color, out)
create(r, g, b, a)
fromHSL(h, s, l, a)
fromHSV(h, s, v, a)
fromHex(hex)
fromLab(l, a, b)
fromRGB(r, g, b, a)
fromRGBBytes(bytes)
fromXYZ(x, y, z)
getHSL(color)
getHSV(color)
getHex(color)
getLab(color)
getRGBBytes(color, out)
getXYZ(color)
lerp
set(color, r, g, b, a)
setHSL(color, h, s, l, a)
setHSV(color, h, s, v, a)
setHex(color, hex)
setLab(color, l, a, b)
setRGB(color, r, g, b, a)
setXYZ(color, x, y, z)
Color.Black
Color.Blue
Color.Cyan
Color.DarkGrey
Color.Green
Color.Grey
Color.LightGrey
Color.Orange
Color.Pink
Color.Red
Color.Transparent
Color.White
Color.Yellow
Reference
## copy(color, out)
Copies color
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|color to copy|
|out|`Array`|color to copy values into|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|new RGBA color array [r,g,b,a] (0..1) or updated out color|
## create(r, g, b, a)
RGBA color constructor function
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|r|`Number`|red component (0..1)|
|g|`Number`|green component (0..1)|
|b|`Number`|blue component (0..1)|
|a|`Number`|alpha component (0..1)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromHSL(h, s, l, a)
Creates new color from hue, saturation, lightness and alpha
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|h|`Number`|hue (0..1)|
|s|`Number`|saturation (0..1)|
|l|`Number`|lightness (0..1)|
|a|`Number`|alpha (0..1)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromHSV(h, s, v, a)
Creates new color from hue, saturation and value
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|h|`Number`|hue (0..1)|
|s|`Number`|saturation (0..1)|
|v|`Number`|value (0..1)|
|a|`Number`|alpha (0..1)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromHex(hex)
Creates new color from html hex string
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|hex|`String`|html hex string #RRGGBB (# is optional)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromLab(l, a, b)
Creates new color from l,a,b component values
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|l|`Number`|l component (0..100)|
|a|`Number`|a component (-128..127)|
|b|`Number`|b component (-128..127)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromRGB(r, g, b, a)
Creates new color from RGBA values. Alias for create(r, g, b, a)
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|r|`Number`|red component (0..1)|
|g|`Number`|green component (0..1)|
|b|`Number`|blue component (0..1)|
|a|`Number`|alpha component (0..1)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromRGBBytes(bytes)
Creates new color from array of 4 byte (0..255) values [r, g, b, a]
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|bytes|`Array`|RGB color byte array [r,g,b,a] (0..255)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## fromXYZ(x, y, z)
Creates new color from XYZ values
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|x|`Number`|x component (0..95)|
|y|`Number`|y component (0..100)|
|z|`Number`|z component (0..108)|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGBA color array [r,g,b,a] (0..1)|
## getHSL(color)
Returns hue, saturation, lightness and alpha of given color.
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|HSLA values array [h,s,l,a] (0..1)|
## getHSV(color)
Get hue, saturation, value and alpha of given color
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|HSVA values array [h,s,v,a] (0..1)|
## getHex(color)
Returns html hex representation of given color
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
#### Returns
| Type | Description |
| --- | --- |
|`String`|html hex color including leading hash e.g. #FF0000|
## getLab(color)
Returns LAB color components
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|LAB values array [h,s,l] (l:0..100, a:-128..127, b:-128..127)|
## getRGBBytes(color, out)
Returns RGB color components as bytes (0..255)
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
|out|`Array`|array to copy values into|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|RGB color byte array [r,g,b] (0..255) or updated out array|
## getXYZ(color)
Returns XYZ representation of given color
#### Parameters
| Name | Type | Description |
| --- | --- | --- |
|color|`Array`|RGBA color array [r,g,b,a]|
#### Returns
| Type | Description |
| --- | --- |
|`Array`|[x,y,z] (x:0..95, y:0..100, z:0..108)|
## lerp
Float (0..1) RGBA Color utility class
## set(color, r, g, b, a)
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
r
Number
red component (0..1)
g
Number
green component (0..1)
b
Number
blue component (0..1)
a
Number
alpha component (0..1)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setHSL(color, h, s, l, a)Updates a color based on hue, saturation, lightness and alpha
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
h
Number
hue (0..1)
s
Number
saturation (0..1)
l
Number
lightness (0..1)
a
Number
alpha (0..1)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setHSV(color, h, s, v, a)Updates a color based on hue, saturation, value and alpha
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
h
Number
hue (0..1)
s
Number
saturation (0..1)
v
Number
value (0..1)
a
Number
alpha (0..1)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setHex(color, hex)Updates a color based on html hex string e.g. #FF0000 -> 1,0,0,1
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
hex
String
html hex string #RRGGBB (# is optional)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setLab(color, l, a, b)Updates a color based on l, a, b, component values
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
l
Number
l component (0..100)
a
Number
a component (-128..127)
b
Number
b component (-128..127)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setRGB(color, r, g, b, a)Updates a color based on r, g, b, a component values
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
r
Number
red component (0..1)
g
Number
green component (0..1)
b
Number
blue component (0..1)
a
Number
alpha component (0..1)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
setXYZ(color, x, y, z)Updates a color based on x, y, z component values
Parameters
Name
Type
Description
color
Array
RGBA color array [r,g,b,a] to update
x
Number
x component (0..95)
y
Number
y component (0..100)
z
Number
z component (0..108)
Returns
Type
Description
Array
updated RGBA color array [r,g,b,a] (0..1)
Color.BlackBlack color [0, 0, 0, 1]
Color.BlueBlue color [0, 0, 1, 1]
Color.CyanCyan color [0, 1, 1, 1]
Color.DarkGreyDark Grey color [0, 0, 0, 1]
Color.GreenGreen color [0, 1, 0, 1]
Color.GreyGrey color [0.5, 0.5, 0.5, 1]
Color.LightGreyLight Grey color [0.75, 0.75, 0.75, 1]
Color.OrangeOrange color [1, 0.5, 0, 1]
Color.PinkPink color [1, 0, 1, 1]
Color.RedRed color [1, 0, 0, 1]
Color.TransparentTransparent color [0, 0, 0, 0]
Color.WhiteWhite color [0, 0, 0, 1]
Color.YellowYellow color [1, 1, 0, 1]