ColorSequence 数据类型代表从 0 到 1 的颜色值渐变。颜色值使用 ColorSequenceKeypoint 输入表达。这种类型用于ParticleEmitter、Trail、Beam和其他使用颜色渐变的对象。
平等
两个 ColorSequence 对象只有在它们的 ColorSequenceKeypoint 值相等时才相等,即使两者都会导致相似的渐变。
评估
ColorSequence 类型没有内置方法来获取特定时间/点的值。然而,您可以使用以下函数在特定时间进行评估。
local function evalColorSequence(sequence: ColorSequence, time: number)
-- 如果时间为 0 或 1,分别返回第一个或最后值
if time == 0 then
return sequence.Keypoints[1].Value
elseif time == 1 then
return sequence.Keypoints[#sequence.Keypoints].Value
end
-- 否则,步过每个顺序的键点对
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
-- 计算点之间的 alpha 距离有多远
local alpha = (time - thisKeypoint.Time) / (nextKeypoint.Time - thisKeypoint.Time)
-- 使用 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
概要
构造工具
返回一个新的 ColorSequence ,完全是指定的颜色。
返回一个新的 ColorSequence ,其起始值为 c0 ,终值为 c1 。
从 ColorSequence 阵列中返回一个新的 ColorSequenceKeypoints 。
属性
一个由 ColorSequenceKeypoint 值排序上升的阵列。
构造工具
new
返回两个关键点的序列,其中 c 用于启动和终止值。
local colorSequence = ColorSequence.new(c)-- 等价于local colorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, c),ColorSequenceKeypoint.new(1, c)}
参数
new
返回一个新的 ColorSequence ,其起始值为 c0 ,终值为 c1 。
local colorSequence = ColorSequence.new(c0, c1)-- 等价于local colorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, c0),ColorSequenceKeypoint.new(1, c1)}
new
从 ColorSequence 阵列中返回一个新的 ColorSequenceKeypoints 。钥匙点必须处于非下降时间值顺序。至少需要提供两个关键点,它们必须有时间值 0 (第一个) 和 1 (最后一个)。
local red = Color3.fromRGB(255, 0, 0)local cyan = Color3.fromRGB(0, 190, 200)local purple = Color3.fromRGB(190, 0, 255)local colorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, red),ColorSequenceKeypoint.new(0.5, cyan),ColorSequenceKeypoint.new(1, purple)}