The problem
So I was going to make a day/night cycle script and I wanted to adjust the ambient color depending on the time of day. Since I want to fade between more than just one color I thought maybe I could use
ColorSequence (ColorSequence | Documentation - Roblox Creator Hub)
Sadly this object doesn’t let you get a color. I understand why since it’s made just to be applied to Trails and such. But there are legitimate situations that would require a get function, such as my ambient setting problem.
Suggestion,
add a function to get the Color3 from a ColorSequence given a percentage value 0-1.
I would love for this to be added. I recently had a usecase for this, and was dissapointed that I couldn’t get a color at a specific part of the ColorSequence.
While this may not be the best way to do it, I ended up deciding to make my own function to do this for me, and it may be useful for others until this feature is addressed.
local function GetColor(Seq, Perc)
local Min, Next = nil;
for i, v in pairs(Seq.Keypoints) do
if (not Min) then
Min, Next = v, Seq.Keypoints[i+1] or v;
else
if (v.Time > Min.Time and v.Time <= Perc) then
Min, Next = v, Seq.Keypoints[i+1] or v;
end
end
end
local Diff = (Perc - Min.Time) / (Next.Time - Min.Time);
return Min.Value:lerp(Next.Value, Diff);
end
Bump, I really don’t understand why this doesn’t exist when we have method like TweenService:GetValue(). It’d add more functionality to a data type that exists solely for instances with a ColorSequence property.
Same can be said for NumberSequence. Something like Godot already got a feature to get value at specific point of the curve and probably many other engines like Unity or Unreal Engine. It would be performant too since the code to get value at point/time would be compiled and low-level.
I’ve had a use-case with editable images already (UIRadialGradient) and it was inconvinient (and inefficent) to loop through ColorSequence’s keypoints (multi-threading helped with performance and i could have real-time effects on 256x256 EditableImage). Maybe baking a sequence would help.