Dev » Lua API » gradient
← Back to all classes

gradient

Math 11 Methods

gradient

The gradient class represents a color ramp with keyframe offsets (0.0 to 1.0). Used for procedural color sampling, particle effects, day/night cycles, and UI bars.

Overview

Methods (11)

Method Signature Returns Summary
gradient:addPoint(offset, color) void Adds a keyframe point to the gradient.
gradient:clearPoints() void Clears all keyframe points from the gradient.
gradient.fromPoints(pointsTable) gradient Creates a gradient from a table of keyframe points.
gradient:getColor(index) color Gets the color at a keyframe point.
gradient:getOffset(index) number Gets the offset position of a keyframe point.
gradient.new() gradient Constructs a new empty gradient.
gradient:pointCount() number Returns the number of keyframe points.
gradient:removePoint(index) void Removes a keyframe point by index.
gradient:sample(offset) color Samples the blended color at the specified ramp position.
gradient:setColor(index, color) void Sets the color at a keyframe point.
gradient:setOffset(index, offset) void Sets the offset position of a keyframe point.

Detailed Reference

# addPoint METHOD
gradient:addPoint(offset, color)
Adds a keyframe point to the gradient.
Parameters
ParameterTypeDefaultDescription
offsetnumber

Keyframe position along ramp (0.0 to 1.0).

colorcolor

Color at this keyframe.

Returns
None (void)
Description

Inserts a new color point at offset.

# clearPoints METHOD
gradient:clearPoints()
Clears all keyframe points from the gradient.
Parameters
None
Returns
None (void)
Description

Resets the gradient back to an empty state.

# fromPoints METHOD
gradient.fromPoints(pointsTable)
Creates a gradient from a table of keyframe points.
Parameters
ParameterTypeDefaultDescription
pointsTabletable

Table containing point definitions with offsets and colors.

Returns
gradient

Configured gradient.

Description

Initializes a gradient ramp from a table of offset/color pairs.

# getColor METHOD
gradient:getColor(index)
Gets the color at a keyframe point.
Parameters
ParameterTypeDefaultDescription
indexnumber

0-based point index.

Returns
color

Color value at keyframe.

Description

Returns the color of the point at index.

# getOffset METHOD
gradient:getOffset(index)
Gets the offset position of a keyframe point.
Parameters
ParameterTypeDefaultDescription
indexnumber

0-based point index.

Returns
number

Offset position (0.0 to 1.0).

Description

Returns the normalized position of the point at index.

# new METHOD
gradient.new()
Constructs a new empty gradient.
Parameters
None
Returns
gradient

Empty gradient.

Description

Creates a gradient with default keyframes.

# pointCount METHOD
gradient:pointCount()
Returns the number of keyframe points.
Parameters
None
Returns
number

Total number of points.

Description

Gets the total count of keyframes in the gradient ramp.

# removePoint METHOD
gradient:removePoint(index)
Removes a keyframe point by index.
Parameters
ParameterTypeDefaultDescription
indexnumber

0-based point index.

Returns
None (void)
Description

Deletes the point at index.

# sample METHOD
gradient:sample(offset)
Samples the blended color at the specified ramp position.
Parameters
ParameterTypeDefaultDescription
offsetnumber

Position on ramp to evaluate (0.0 to 1.0).

Returns
color

Evaluated blended color.

Description

Evaluates the gradient and returns the interpolated color at offset.

local midColor = ramp:sample(0.5)
# setColor METHOD
gradient:setColor(index, color)
Sets the color at a keyframe point.
Parameters
ParameterTypeDefaultDescription
indexnumber

0-based point index.

colorcolor

New color value.

Returns
None (void)
Description

Updates the color of the point at index.

# setOffset METHOD
gradient:setOffset(index, offset)
Sets the offset position of a keyframe point.
Parameters
ParameterTypeDefaultDescription
indexnumber

0-based point index.

offsetnumber

New offset position (0.0 to 1.0).

Returns
None (void)
Description

Reposition the keyframe point at index to offset.