OPX//77
opx_lib

Lib.Colour

Last updated on

Parse

Pure. No permission. A colour is { r, g, b } (integers 0–255); HSL is { h, s, l } (degrees, 0..1, 0..1).

Lib.Colour.Parse

Parses '#RRGGBB'.

Lib.Colour.Parse(value)

Parameters

  • value: any

Returns

  • { r, g, b }?
Example
local accent = Lib.Colour.Parse(config.ACCENT) or { r = 0, g = 255, b = 255 }

Lib.Colour.Hex

Back to '#RRGGBB'.

Lib.Colour.Hex(colour)

Parameters

  • colour: { r, g, b }

Returns

  • string

Lib.Colour.ToHsl

RGB to HSL.

Lib.Colour.ToHsl(colour)

Parameters

  • colour: { r, g, b }

Returns

  • { h, s, l }

Lib.Colour.FromHsl

HSL to RGB.

Lib.Colour.FromHsl(hsl)

Parameters

  • hsl: { h, s, l }

Returns

  • { r, g, b }

Lib.Colour.Shade

The same colour, lighter or darker by a lightness offset.

Lib.Colour.Shade(colour, by)

Parameters

  • colour: { r, g, b }
  • by: number
    • -1..1.

Returns

  • { r, g, b }
Example
local hover = Lib.Colour.Shade(accent, 0.15)

Lib.Colour.Saturate

More or less saturated, by a fraction of its own saturation.

Lib.Colour.Saturate(colour, fraction)

Parameters

  • colour: { r, g, b }
  • fraction: number

Returns

  • { r, g, b }

Lib.Colour.Mix

A blend of two colours, in RGB.

Lib.Colour.Mix(from, to, amount)

Parameters

  • from: { r, g, b }
  • to: { r, g, b }
  • amount: number
    • 0..1.

Returns

  • { r, g, b }

Lib.Colour.Luminance

Perceived brightness.

Lib.Colour.Luminance(colour)

Parameters

  • colour: { r, g, b }

Returns

  • number — 0..1

Lib.Colour.Contrast

Whichever of two colours reads better on background.

Lib.Colour.Contrast(background, onLight, onDark)

Parameters

  • background: { r, g, b }
  • onLight?: { r, g, b }
    • Default: black.
  • onDark?: { r, g, b }
    • Default: white.

Returns

  • { r, g, b }
Example
local text = Lib.Colour.Hex(Lib.Colour.Contrast(accent))

On this page