#How do i select a specific point of a UIGradient
38 messages · Page 1 of 1 (latest)
Well, Roblox is stupid and can't implement a simple method for ColorSequences
but here you go
local function EvalColorSequence(sequence: ColorSequence, timer: number): Color3
if timer == 0 then
return sequence.Keypoints[1].Value
elseif timer == 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 timer >= thisKeypoint.Time and timer < nextKeypoint.Time then
local alpha = (timer - thisKeypoint.Time) / (nextKeypoint.Time - thisKeypoint.Time)
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
@tender bridge example how to use this
local MiddleColor = EvalColorSequence(UIGradient.Color, 0.5)
So stupid
Ikr
** You are now Level 13! **
Would be easy(?) to implement renaming points, and just doing gradient.point1
Just treat it as a property
Not for you, no.
But making that a studio feature
roblox should make that
Mm eh
I think just making that function an in-built method for ColorSequence would be much better
Yeah, that was what i meant
Roblox should make a way of selecting a point
Yeah but naming them is kinda stupid
Maybe just add every point as a property
Noone is gonna have 1000 points on a gradient
Yes but there's always 1,000 points in a ColorSequence
No, every point added
local NewColorSequence = {}
NewColorSequence.__index = NewColorSequence
function NewColorSequence.new(sequence: ColorSequence)
local self = setmetatable({}, NewColorSequence)
self._sequence = sequence
return self
end
function NewColorSequence:Eval(t: number): Color3
if t == 0 then
return self._sequence.Keypoints[1].Value
elseif t == 1 then
return self._sequence.Keypoints[#self._sequence.Keypoints].Value
end
for i = 1, #self._sequence.Keypoints - 1 do
local thisKeypoint = self._sequence.Keypoints[i]
local nextKeypoint = self._sequence.Keypoints[i + 1]
if t >= thisKeypoint.Time and t < nextKeypoint.Time then
local alpha = (t - thisKeypoint.Time) / (nextKeypoint.Time - thisKeypoint.Time)
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
return NewColorSequence
I made this module
you can like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NewColorSequence = require(ReplicatedStorage.NewColorSequence)
local Sequence = ColorSequence.new(Color3.fromRGB(243, 41, 27), Color3.fromRGB(98, 255, 70))
local NewSequence = NewColorSequence.new(Sequence)
print(NewSequence:Eval(0.5)) -- Prints the color in the middle
I understand
These should be a property
Anyways, thanks for fixing my problem