gradient
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
gradient:addPoint(offset, color)| Parameter | Type | Default | Description |
|---|---|---|---|
offset | number | Keyframe position along ramp (0.0 to 1.0). | |
color | color | Color at this keyframe. |
Inserts a new color point at offset.
gradient:clearPoints()Resets the gradient back to an empty state.
gradient.fromPoints(pointsTable)| Parameter | Type | Default | Description |
|---|---|---|---|
pointsTable | table | Table containing point definitions with offsets and colors. |
gradientConfigured gradient.
Initializes a gradient ramp from a table of offset/color pairs.
gradient:getColor(index)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 0-based point index. |
colorColor value at keyframe.
Returns the color of the point at index.
gradient:getOffset(index)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 0-based point index. |
numberOffset position (0.0 to 1.0).
Returns the normalized position of the point at index.
gradient.new()gradientEmpty gradient.
Creates a gradient with default keyframes.
gradient:pointCount()numberTotal number of points.
Gets the total count of keyframes in the gradient ramp.
gradient:removePoint(index)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 0-based point index. |
Deletes the point at index.
gradient:sample(offset)| Parameter | Type | Default | Description |
|---|---|---|---|
offset | number | Position on ramp to evaluate (0.0 to 1.0). |
colorEvaluated blended color.
Evaluates the gradient and returns the interpolated color at offset.
local midColor = ramp:sample(0.5)gradient:setColor(index, color)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 0-based point index. | |
color | color | New color value. |
Updates the color of the point at index.
gradient:setOffset(index, offset)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 0-based point index. | |
offset | number | New offset position (0.0 to 1.0). |
Reposition the keyframe point at index to offset.