Skip to content

Gradient

Types

GradientKeypoint

{
    Time: number,
    Color: Color
}

Time must be in the range [0, 1].

Constructors

Gradient.new

Static function

Gradient.new(keypoints: array<GradientKeypoint>): Gradient

Standard Gradient constructor. The first keypoint must have a Time of 0, and the last keypoint must have a Time of 1. (Consequently, there must be at least 2 keypoints.) The keypoint list must be sorted by time.


Gradient.fromColors

Static function

Gradient.fromColors(...: Color): Gradient

Creates a Gradient from one or more Colors. If one Color is passed, the start and end keypoints will have the same color. If two Colors are passed, the start and end keypoints will have the first and second color, respectively. If 3 or more Colors is passed, the keypoints will be equidistant with respect to time.


Gradient.fromColorSequence

Static function

Gradient.fromColorSequence(colorSequence: ColorSequence): Gradient

Creates a Gradient from a ColorSequence.


Properties

Gradient.Keypoints

Static function

Gradient.Keypoints: array<GradientKeypoint>

Functions

Gradient.invert

Gradient.invert(gradient: Gradient): Gradient

Returns a Gradient with reversed keypoints.


Gradient.color

Gradient.color(gradient: Gradient, time: number, mode: string? = "RGB", hueAdjustment: string? = "Shorter"): Color

Returns a Color from the Gradient at the specified time, mixing mode, and hue adjustment (see Color.mix for what those are). time should be in the range [0, 1].


Gradient.colors

Gradient.colors(gradient: Gradient, amount: number?, mode: string? = "RGB", hueAdjustment: string? = "Shorter"): array<Color>

Returns an array of amount equidistant colors, using the specified mixing mode and hue adjustment (see Color.mix for what those are).


Gradient.colorSequence

Gradient.colorSequence(gradient: Gradient, steps: number? = 20, mode: string? = "RGB", hueAdjustment: string? = "Shorter"): ColorSequence

Returns a ColorSequence with steps equidistant colors. If the mixing mode is RGB, the ColorSequence will instead consist of the colors from the GradientKeypoints used to construct it.

Info

Due to an engine limitation that only allows up to 20 keypoints in a ColorSequence, you may notice differences between the ColorSequence's intermediate colors and the Gradient's intermediate colors if you are using a mixing mode other than RGB.

Math Operations

Gradient == Gradient

Comparing Gradients with == checks if they have the same number of keypoints, that the keypoints have the same Time values, and that the keypoints have the same Color values (using Color.unclippedEq).

local gradient1 = Gradient.fromColors(
    Color.new(0, 0, 0),
    Color.new(1, 1, 1)
)

local gradient2 = Gradient.new({
    {Time = 0, Color = Color.new(0, 0, 0)},
    {Time = 1, Color = Color.new(1, 1, 1)}
})

local gradient3 = Gradient.new({
    {Time = 0, Color = Color.new(1, 1, 1)},
    {Time = 1, Color = Color.new(0, 0, 0)}
}) 

print(gradient1 == gradient2) --> true
print(gradient1 == gradient3) --> false
print(gradient1 == gradient3:invert()) --> true