Skip to content

Color

The Color library offers utilities for working with colors, either through RGB, decimal, or hex.

The constructor methods create an RGBColor table.

The library also contains constants for common colors used by Larian.

ColorLib Class

Methods

Clone
function ColorLib.Clone(color)
   -> RGBColor -- New instance with same values.

Clones a color instance.

@param color RGBColor

Create
function ColorLib.Create(red, green, blue, alpha)
   -> RGBColor

Alias for creating an RGBColor from RGBA values.

@param red integer?

@param green integer?

@param blue integer?

@param alpha integer?

CreateFromDecimal
function ColorLib.CreateFromDecimal(num)
   -> RGBColor

Creates a color from a decimal value.

Does not support alpha.

@param num integer

CreateFromHex
function ColorLib.CreateFromHex(hex)
   -> RGBColor

Creates a color from an html-format hex color code.

Does not support alpha.

@param hex string

CreateFromRGB
function ColorLib.CreateFromRGB(red, green, blue, alpha)
   -> RGBColor

Creates a color from RGBA values. Expected range of values is [0-255].

@param red integer?

@param green integer?

@param blue integer?

@param alpha integer?

Lerp
function ColorLib.Lerp(startColor, targetColor, progress)

Creates a new color whose RGB components are linearly interpolated from one to another.

Uses the alpha of the target color.

@param startColor RGBColor

@param targetColor RGBColor

@param progress number Expected values are from 0.0 to 1.0.

RGBColor Class

Methods

Clone
function RGBColor:Clone()
   -> RGBColor

Returns a new instance of RGBColor with the same values.

Create
function RGBColor.Create(r, g, b, a)
   -> RGBColor

Creates a color from RGBA values.

Expected range is [0-255] and will be clamped.

@param r integer?

@param g integer?

@param b integer?

@param a integer? Defaults to 255.

CreateFromDecimal
function RGBColor.CreateFromDecimal(num)
   -> RGBColor

Creates a color from a decimal value.

Does not support alpha.

@param num integer

CreateFromHex
function RGBColor.CreateFromHex(hex)
   -> RGBColor

Creates a color from a hexadecimal value.

Does not support alpha.

@param hex string

Equals
function RGBColor:Equals(color)
   -> boolean

Returns whether 2 colors have the same RGBA values.

@param color RGBColor

ToDecimal
function RGBColor:ToDecimal(addAlpha)
   -> integer

Returns the decimal representation of the color.

Actionscript expects colors to be represented in this way.

@param addAlpha boolean? Defaults to false.

ToFloats
function RGBColor:ToFloats()
   -> number, number, number, number

Returns the RGBA values as floats in the range[0.0 - 1.0]

ToHex
function RGBColor:ToHex(prefix, addAlpha)
   -> string

Returns the hexadecimal representation of the color.

@param prefix boolean? Prefix the string with #. Defaults to false.

@param addAlpha boolean? Defaults to false. If enabled, resulting color will be in the format `#RRGGBBAA`

Unpack
function RGBColor:Unpack()
   -> integer ...

Unpacks the color's RGB values, alpha included.

__add
---@protected
function RGBColor.__add(color1, color2)
   -> RGBColor

__add overload. Adds the RGB values of both colors.

@param color1 RGBColor

@param color2 RGBColor

__eq
---@protected
function RGBColor.__eq(color1, color2)
   -> boolean

__eq overload. Equivalent to calling RGBColor:Equals()

@param color1 RGBColor

@param color2 RGBColor

__sub
---@protected
function RGBColor.__sub(color1, color2)
   -> RGBColor

__sub overload. Subtracts the RGB values.

@param color1 RGBColor

@param color2 RGBColor