#How do i select a specific point of a UIGradient

38 messages · Page 1 of 1 (latest)

tender bridge
#

how

trim leaf
#

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)
trim leaf
#

Ikr

heady prawnBOT
#

studio** You are now Level 13! **studio

tender bridge
# trim leaf Ikr

Would be easy(?) to implement renaming points, and just doing gradient.point1

#

Just treat it as a property

trim leaf
#

no

#

It's not even possible

#

but you can store them inside of a table

tender bridge
#

But making that a studio feature

#

roblox should make that

trim leaf
#

Mm eh

#

I think just making that function an in-built method for ColorSequence would be much better

tender bridge
#

Roblox should make a way of selecting a point

trim leaf
#

Yeah but naming them is kinda stupid

tender bridge
trim leaf
#

1000 points?

#

why

tender bridge
trim leaf
#

Yes but there's always 1,000 points in a ColorSequence

tender bridge
trim leaf
#
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
tender bridge
trim leaf
#

I understand

tender bridge
#

These should be a property

trim leaf
#

nah that's a really bad idea

#

because you can already get those

tender bridge