Try Install Learn Blog API Packages GitHub
Pages

Color

Functions to create and manipulate colors.

Functions

fromHEX
(
value
:
String
)
:
Maybe(Color)

Creates a color from a HEX part.

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)
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
lighten
(
ratio
:
Number
color
:
Color
)
:
Color
mix
(
weight
:
Number
color1
:
Color
color2
:
Color
)
:
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(0.5, color1, color2) == Color.fromRGBA(128, 128, 128, 100)

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)
setAlpha
(
alpha
:
Number
color
:
Color
)
:
Color
setLightness
(
lightness
:
Number
color
:
Color
)
:
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
(
saturation
:
Number
color
:
Color
)
:
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
(
value
:
Number
color
:
Color
)
:
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)
toCSSRGBA
(
color
:
Color
)
:
String

Converts the given color to the CSS RGBA represenation.

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

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

Converts the internal represenation of the color to HEX.

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

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

Converts the internal represenation of the color to RGBA.

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 represenation 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 represenation of the color to RGBA.

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

Color.toRGBA(color) == Color.fromRGBA(255, 255, 255, 100)
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}