Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: color · Entries: 29
color (library)
Definition
Seven functions: color.new and color.rgb build a colour, color.from_gradient builds one between two colours, and color.r, color.g, color.b and color.a read one apart. Seventeen named colour constants sit alongside them.
Seven is the whole namespace. There is no separate transparency function — set opacity with color.new on a colour you already have. color.new, color.r, color.g, color.b and color.a return na when the colour they are given is na.
Example
color.a (function, overload 1)
Definition
Reads the opacity of a colour.
Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.
Syntax
Returns
const float
Example
color.a (function, overload 2)
Definition
Reads the opacity of a colour.
Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.
Syntax
Returns
input float
Example
color.a (function, overload 3)
Definition
Reads the opacity of a colour.
Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.
Syntax
Returns
simple float
Example
color.a (function, overload 4)
Definition
Reads the opacity of a colour.
Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.
Syntax
Returns
series float
Example
color.b (function, overload 1)
Definition
Reads the blue component of a colour.
Its result is an int from 0 to 255, as with red and green.
Syntax
Returns
const int
Example
color.b (function, overload 2)
Definition
Reads the blue component of a colour.
Its result is an int from 0 to 255, as with red and green.
Syntax
Returns
input int
Example
color.b (function, overload 3)
Definition
Reads the blue component of a colour.
Its result is an int from 0 to 255, as with red and green.
Syntax
Returns
simple int
Example
color.b (function, overload 4)
Definition
Reads the blue component of a colour.
Its result is an int from 0 to 255, as with red and green.
Syntax
Returns
series int
Example
color.from_gradient (function, overload 1)
Definition
Returns a color calculated from the linear gradient between bottom_color and top_color based on the relative position of value within the range defined by bottom_value and top_value.
Syntax
Returns
const color
const color
Example
color.from_gradient (function, overload 2)
Definition
Returns a color calculated from the linear gradient between bottom_color and top_color based on the relative position of value within the range defined by bottom_value and top_value.
Syntax
Returns
input color
input color
Example
color.from_gradient (function, overload 3)
Definition
Returns a color calculated from the linear gradient between bottom_color and top_color based on the relative position of value within the range defined by bottom_value and top_value.
Syntax
Returns
simple color
simple color
Example
color.from_gradient (function, overload 4)
Definition
Returns a color calculated from the linear gradient between bottom_color and top_color based on the relative position of value within the range defined by bottom_value and top_value.
Syntax
Returns
series color
series color
Example
color.g (function, overload 1)
Definition
Reads the green component of a colour.
Like the other two component functions, it returns a whole number from 0 to 255.
Syntax
Returns
const int
Example
color.g (function, overload 2)
Definition
Reads the green component of a colour.
Like the other two component functions, it returns a whole number from 0 to 255.
Syntax
Returns
input int
Example
color.g (function, overload 3)
Definition
Reads the green component of a colour.
Like the other two component functions, it returns a whole number from 0 to 255.
Syntax
Returns
simple int
Example
color.g (function, overload 4)
Definition
Reads the green component of a colour.
Like the other two component functions, it returns a whole number from 0 to 255.
Syntax
Returns
series int
Example
color.new (function, overload 1)
Definition
Takes a colour and an opacity, and returns that colour at that opacity.
Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example opacity 50 is outside 0–1; 1 is solid.
Syntax
Returns
const color
Notes
alphais an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warningopacity 50 is outside 0–1; 1 is solid.
color.new (function, overload 2)
Definition
Takes a colour and an opacity, and returns that colour at that opacity.
Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example opacity 50 is outside 0–1; 1 is solid.
Syntax
Returns
input color
Notes
alphais an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warningopacity 50 is outside 0–1; 1 is solid.
color.new (function, overload 3)
Definition
Takes a colour and an opacity, and returns that colour at that opacity.
Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example opacity 50 is outside 0–1; 1 is solid.
Syntax
Returns
simple color
Notes
alphais an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warningopacity 50 is outside 0–1; 1 is solid.
color.new (function, overload 4)
Definition
Takes a colour and an opacity, and returns that colour at that opacity.
Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example opacity 50 is outside 0–1; 1 is solid.
Syntax
Returns
series color
Notes
alphais an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warningopacity 50 is outside 0–1; 1 is solid.
color.r (function, overload 1)
Definition
Reads the red component back out of a colour.
The figure comes back on the scale it went in on, 0 to 255.
Syntax
Returns
const int
Example
color.r (function, overload 2)
Definition
Reads the red component back out of a colour.
The figure comes back on the scale it went in on, 0 to 255.
Syntax
Returns
input int
Example
color.r (function, overload 3)
Definition
Reads the red component back out of a colour.
The figure comes back on the scale it went in on, 0 to 255.
Syntax
Returns
simple int
Example
color.r (function, overload 4)
Definition
Reads the red component back out of a colour.
The figure comes back on the scale it went in on, 0 to 255.
Syntax
Returns
series int
Example
color.rgb (function, overload 1)
Definition
Builds a colour from red, green and blue components, with an optional opacity.
Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.
Syntax
Returns
const color
Example
color.rgb (function, overload 2)
Definition
Builds a colour from red, green and blue components, with an optional opacity.
Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.
Syntax
Returns
input color
Example
color.rgb (function, overload 3)
Definition
Builds a colour from red, green and blue components, with an optional opacity.
Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.
Syntax
Returns
simple color
Example
color.rgb (function, overload 4)
Definition
Builds a colour from red, green and blue components, with an optional opacity.
Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.
Syntax
Returns
series color
Example