ColorSequence

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

ColorSequence 數據類型代表從 01 的顏色值渐變。顏色值使用 ColorSequenceKeypoint 輸入型表達。這種類型在 ParticleEmitterTrailBeam 和其他使用顏色傾斜的對象中被使用。

平等

兩個 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

概要

建構子

屬性

建構子

new

返回兩個關鍵點的順序,並以 c 為開始和結束值。


local colorSequence = ColorSequence.new(c)
-- 等值於
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, c),
ColorSequenceKeypoint.new(1, c)
}

參數

new

返回新的 ColorSequencec0 作為起始值和 c1 作為終值。


local colorSequence = ColorSequence.new(c0, c1)
-- 等值於
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, c0),
ColorSequenceKeypoint.new(1, c1)
}

參數

c0: Color3
c1: Color3

new

從一個 ColorSequenceKeypoints 陣列中返回新的 ColorSequence 。關鍵點必須處於非下降時間值順序。至少必須提供兩個關鍵點,且它們必須具有時間值 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)
}

參數

keypoints: Array

屬性

Keypoints

包含 ColorSequenceKeypoint 值的陣列,用於 ColorSequence