Try Install Learn Blog API Packages GitHub
Pages

Color

Functions

colorOfString
(
value
:
String
)
:
String

Generates a color from a string.

contrastRatio
(
background
:
Color
text
:
Color
)
:
Number

Calculates the color contrast ratio between two colors (1 to 21). https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast

fromHEX
(
value
:
String
)
:
Maybe(Color)

Creates a color from a HEX string.

Color.fromHEX("#FFF")
Color.fromHEX("#FFFFFF")
Color.fromHEX("#FFFFFFFF")
fromHSVA
(
hue
:
Number
saturation
:
Number
value
:
Number
alpha
:
Number
)
:
Color

Creates a color from hue, saturation, value and alpha parts.

Color.fromHSVA(0, 100, 100, 100)
fromRGBA
(
red
:
Number
green
:
Number
blue
:
Number
alpha
:
Number
)
:
Color

Creates a color from red, green, blue and alpha parts.

Color.fromRGBA(255, 255, 255, 100)
getAlpha
(
color
:
Color
)
:
Number

Returns the alpha value of the color.

Color.getAlpha(Color.fromHSVA(0,100,100,50)) == 50
getBrightness
(
color
:
Color
)
:
Number

Returns the brightness of the given color base on the W3C formula

Color.getBrightness(Color.fromRGBA(255,255,255,100)) == 1000
Color.getBrightness(Color.fromRGBA(0,0,0,100)) == 0
getHue
(
color
:
Color
)
:
Number

Returns the hue of the color.

Color.getHue(Color.fromHSVA(0,100,100,50)) == 0
getSaturation
(
color
:
Color
)
:
Number

Returns the saturation of the color.

Color.getSaturation(Color.fromHSVA(0,100,100,50)) == 100
getValue
(
color
:
Color
)
:
Number

Returns the value of the color.

Color.getValue(Color.fromHSVA(0,100,100,50)) == 100
lighten
(
color
:
Color
ratio
:
Number
)
:
Color

Makes the color lighter using the given ratio.

color =
  Color.fromHSLA(0, 100, 10, 100)

Color.lighten(color, 10) == Color.fromHSLA(0, 100, 100, 100)
mix
(
color1
:
Color
color2
:
Color
weight
:
Number
)
:
Color

Mixes two given colors using the given weight (0..1).

color1 =
  Color.fromRGBA(255, 255, 255, 100)

color2 =
  Color.fromRGBA(0, 0, 0, 100)

Color.mix(color1, color2, 0.5) == Color.fromRGBA(128, 128, 128, 100)
random
:
Color

Generates a random color.

readableTextColor
(
color
:
Color
)
:
Color

Returns the readable text color (white or black) based on the brightness of the color.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.readableTextColor(color) == Color.fromRGBA(0, 0, 0, 100)
relativeLuminance
(
color
:
Color
)
:
Number

Calculates the relative luminance of a color. https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef

setAlpha
(
color
:
Color
alpha
:
Number
)
:
Color

Sets the alpha to the given value of the given color.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.setAlpha(color, 50) == Color.fromHSVA(0, 100, 100, 50)
setHue
(
color
:
Color
hue
:
Number
)
:
Color

Sets the hue to the given value of the given color.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.setHue(color, 50) == Color.fromHSVA(50, 100, 100, 100)
setLightness
(
color
:
Color
lightness
:
Number
)
:
Color

Sets the lightness to the given value of the given color.

color =
  Color.fromHSLA(0, 100, 100, 100)

Color.setLightness(50, color) == Color.fromHSLA(0, 100, 50, 100)
setSaturation
(
color
:
Color
saturation
:
Number
)
:
Color

Sets the saturation to the given value of the given color.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.setSaturation(50, color) == Color.fromHSVA(0, 50, 100, 100)
setValue
(
color
:
Color
value
:
Number
)
:
Color

Sets the value to the given value of the given color.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.setValue(50, color) == Color.fromHSVA(0, 100, 50, 100)
toCSSHSLA
(
color
:
Color
)
:
String

Returns the CSS HSLA representation of the color.

toCSSHex
(
color
:
Color
)
:
String

Converts the given color to the CSS HEX representation.

color =
  Color.fromHex("#FFF")

Color.toCSSHex(color) == "#FFFFFFFF"
toCSSRGBA
(
color
:
Color
)
:
String

Converts the given color to the CSS RGBA representation.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toCSSRGBA(color) == "rgba(255,255,255,1)"
toCSSRGBAPercent
(
color
:
Color
)
:
String

Returns the CSS Percent RGBA representation of the color.

toHEX
(
color
:
Color
)
:
Color

Converts the internal representation of the color to HEX.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.toHEX(color) == Color.fromHEX("#FFFFFFFF")
toHSIA
(
color
:
Color
)
:
Color

Converts the internal representation of the color to HSIA.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toHSIA(color) == Color.fromHSVA(0, 100, 100, 100)
toHSLA
(
color
:
Color
)
:
Color

Converts the internal representation of the color to HSLA.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toHSLA(color) == Color.fromHSLA(0, 100, 100, 100)
toHSLATuple
(
color
:
Color
)
:
Tuple(Number, Number, Number, Number)

Returns the given color as a HSLA tuple.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toHSLATuple(color) == {255,255,255,100}
toHSVA
(
color
:
Color
)
:
Color

Converts the internal representation of the color to HSVA.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toHSVA(color) == Color.fromHSVA(0, 100, 100, 100)
toRGBA
(
color
:
Color
)
:
Color

Converts the internal representation of the color to RGBA.

color =
  Color.fromHSVA(0, 100, 100, 100)

Color.toRGBA(color) == Color.fromRGBA(255, 255, 255, 100)
toRGBAPercentTuple
(
color
:
Color
)
:
Tuple(Number, Number, Number, Number)

Returns the the color as an Percent RGBA tuple (0..1).

toRGBATuple
(
color
:
Color
)
:
Tuple(Number, Number, Number, Number)

Returns the given color as an RGBA tuple.

color =
  Color.fromRGBA(255, 255, 255, 100)

Color.toRGBATuple(color) == {255,255,255,100}