ColorUtil

Colour helpers for overlays and panels.

Methods
14
Fields
3

Methods

MethodReturnsDescription
colorTag(Color)string<col=rrggbb>.
prependColorTag(string, Color)string<col=rrggbb>str.
wrapWithColorTag(string, Color)string<col=rrggbb>str</col>.
toHexColor(Color)string#rrggbb.
colorLerp(Color, Color, number)ColorEach channel, alpha included, interpolated and rounded half up; a t that pushes a channel out of range is an error.
colorToHexCode(Color)stringrrggbb, lower case.
colorToAlphaHexCode(Color)stringaarrggbb, lower case.
colorWithAlpha(Color, number)ColorThe same RGB with alpha, clamped to 0-255.
isAlphaHex(string)booleanWhether hex is (#|0x)? and 7-8 hex digits.
isHex(string)booleanWhether hex is (#|0x)? and 1-8 hex digits.
constrainValue(number)numbervalue clamped to 0-255.
fromString(string)Color?string as an integer (#rrggbb, 0x..., decimal, octal) read as ARGB, or nil when it does not decode.
fromHex(string)Color?Six digits or fewer opaque, more read as ARGB; nil when it does not decode.
fromObject(any)ColorA saturated, bright colour whose hue comes from a hash of the object: a string, integer or boolean; anything else raises.

Fields

FieldTypeDescription
MAX_RGB_VALUEnumberColorUtil.MAX_RGB_VALUE: 255.
MIN_RGB_VALUEnumberColorUtil.MIN_RGB_VALUE: 0.
CLOSING_COLOR_TAGstringColorUtil.CLOSING_COLOR_TAG: "</col>".

Method details

colorLerp

colorLerp: (Color, Color, number) -> Color

Each channel, alpha included, interpolated and rounded half up; a t that pushes a channel out of range is an error.

isAlphaHex

isAlphaHex: (string) -> boolean

Whether hex is (#|0x)? and 7-8 hex digits.

isHex

isHex: (string) -> boolean

Whether hex is (#|0x)? and 1-8 hex digits.

constrainValue

constrainValue: (number) -> number

value clamped to 0-255.

fromString

fromString: (string) -> Color?

string as an integer (#rrggbb, 0x..., decimal, octal) read as ARGB, or nil when it does not decode.

fromHex

fromHex: (string) -> Color?

Six digits or fewer opaque, more read as ARGB; nil when it does not decode.

fromObject

fromObject: (any) -> Color

A saturated, bright colour whose hue comes from a hash of the object: a string, integer or boolean; anything else raises.