Data type
ColorSequence
A gradient of color values comprised of
ColorSequenceKeypoints.
About ColorSequence
The ColorSequence data type represents a gradient of color values
from 0 to 1. The color values are expressed using the
ColorSequenceKeypoint type. This type is used in various properties
of ParticleEmitter, Trail, Beam, and other objects
that use color gradients.
Equality
Two ColorSequence objects are equivalent only if the values of
their ColorSequenceKeypoint are equivalent, even if both would
result in similar gradients.
Evaluation
The ColorSequence type does not have a built-in method for getting
the value at a certain time/point. However, you can use the following function
to evaluate at a specific time.
local function evalColorSequence(sequence: ColorSequence, time: number)
-- If time is 0 or 1, return the first or last value respectively
if time == 0 then
return sequence.Keypoints[1].Value
elseif time == 1 then
return sequence.Keypoints[#sequence.Keypoints].Value
end
-- Otherwise, step through each sequential pair of keypoints
for i = 1, #sequence.Keypoints - 1 do
local thisKeypoint = sequence.Keypoints[i]
local nextKeypoint = sequence.Keypoints[i + 1]
if time >= thisKeypoint.Time and time < nextKeypoint.Time then
-- Calculate how far alpha lies between the points
local alpha = (time - thisKeypoint.Time) / (nextKeypoint.Time - thisKeypoint.Time)
-- Evaluate the real value between the points using alpha
return Color3.new(
(nextKeypoint.Value.R - thisKeypoint.Value.R) * alpha + thisKeypoint.Value.R,
(nextKeypoint.Value.G - thisKeypoint.Value.G) * alpha + thisKeypoint.Value.G,
(nextKeypoint.Value.B - thisKeypoint.Value.B) * alpha + thisKeypoint.Value.B
)
end
end
end
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 190, 200)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(190, 0, 255))
}
print(evalColorSequence(colorSequence, 0.75)) --> 0.372549, 0.372549, 0.892157
Constructors 3
ColorSequence.new
(c: Color3)Returns a newColorSequencethat is entirely the specified color.ColorSequence.new
(c0: Color3, c1: Color3)Returns a newColorSequencewithc0as the start value andc1as the end value.ColorSequence.new
(keypoints: Array)Returns a newColorSequencefrom an array ofColorSequenceKeypoints.
Properties 1
Keypoints
: ArrayAn array ofColorSequenceKeypointvalues in ascending order.An array containing
ColorSequenceKeypointvalues for theColorSequence.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.