Dev » Lua API » color
← Back to all classes

color

Math 4 Properties 7 Methods

color

The color class represents RGBA color values with channels normalized from 0.0 to 1.0. Supports hex HTML parsing, byte channel creation (color8), linear interpolation, darkening, and lightening.

Overview

Properties (4)

Property Type Summary
a number Alpha (transparency) channel.
b number Blue color channel.
g number Green color channel.
r number Red color channel.

Methods (7)

Method Signature Returns Summary
color.color8(r, g, b, [a = 255]) color Constructs a color from 0-255 integer byte values.
color:darkened(amount) color Returns a darkened version of the color.
color.fromHtml(html) color Creates a color from an HTML/hex string.
color:inverted() color Returns the color with inverted RGB channels.
color:lerp(to, weight) color Linearly interpolates between colors.
color:lightened(amount) color Returns a lightened version of the color.
color.new(r, g, b, [a = 1.0]) color Constructs a color from normalized float values.

Detailed Reference

# a PROPERTY
color.a
Alpha (transparency) channel.
Parameters
None
Returns
number

Alpha channel (0.0 to 1.0).

Description

Gets or sets the alpha component.

# b PROPERTY
color.b
Blue color channel.
Parameters
None
Returns
number

Blue channel (0.0 to 1.0).

Description

Gets or sets the blue component.

# g PROPERTY
color.g
Green color channel.
Parameters
None
Returns
number

Green channel (0.0 to 1.0).

Description

Gets or sets the green component.

# r PROPERTY
color.r
Red color channel.
Parameters
None
Returns
number

Red channel (0.0 to 1.0).

Description

Gets or sets the red component.

# color8 METHOD
color.color8(r, g, b, [a = 255])
Constructs a color from 0-255 integer byte values.
Parameters
ParameterTypeDefaultDescription
rnumber

Red byte (0 - 255).

gnumber

Green byte (0 - 255).

bnumber

Blue byte (0 - 255).

anumber`255`

Alpha byte (0 - 255).

Returns
color

Newly created color.

Description

Creates a color using standard 8-bit integer channel values.

# darkened METHOD
color:darkened(amount)
Returns a darkened version of the color.
Parameters
ParameterTypeDefaultDescription
amountnumber

Darkening percentage (0.0 - 1.0).

Returns
color

Darkened color.

Description

Interpolates the color toward black.

# fromHtml METHOD
color.fromHtml(html)
Creates a color from an HTML/hex string.
Parameters
ParameterTypeDefaultDescription
htmlstring

Hex string such as "#FFAA00" or "#FF000088".

Returns
color

Parsed color object.

Description

Parses standard HTML hex color notation.

local red = color.fromHtml("#FF0000")
# inverted METHOD
color:inverted()
Returns the color with inverted RGB channels.
Parameters
None
Returns
color

Inverted color.

Description

Calculates $(1-r, 1-g, 1-b, a)$.

# lerp METHOD
color:lerp(to, weight)
Linearly interpolates between colors.
Parameters
ParameterTypeDefaultDescription
tocolor

Target color.

weightnumber

Interpolation factor (0.0 - 1.0).

Returns
color

Interpolated color.

Description

Performs linear blend between this color and to.

# lightened METHOD
color:lightened(amount)
Returns a lightened version of the color.
Parameters
ParameterTypeDefaultDescription
amountnumber

Lightening percentage (0.0 - 1.0).

Returns
color

Lightened color.

Description

Interpolates the color toward white.

# new METHOD
color.new(r, g, b, [a = 1.0])
Constructs a color from normalized float values.
Parameters
ParameterTypeDefaultDescription
rnumber

Red channel (0.0 - 1.0).

gnumber

Green channel (0.0 - 1.0).

bnumber

Blue channel (0.0 - 1.0).

anumber`1.0`

Alpha channel (0.0 - 1.0).

Returns
color

Newly created color.

Description

Creates a color with specified RGBA channels.

local c = color.new(1.0, 0.5, 0.0, 1.0)