Is there anyway to get the color of a specific section of gradient via code?
I have this gradient, I’m wanting to get a specific Color3 from a section of the gradient using code. So if I want say color at 0.26 of the ColorSequence, I can just grab it? I don’t want to have to do this manually, as ideally I needa be able to grab 100+ segments on request
function getColor(percentage, ColorKeyPoints)
if (percentage < 0) or (percentage>1) then
warn'getColor got out of bounds percentage (less than 0 or greater than 1'
end
local closestToLeft = ColorKeyPoints[1]
local closestToRight = ColorKeyPoints[#ColorKeyPoints]
local LocalPercentage = .5
local color = closestToLeft.Value
for i=1,#ColorKeyPoints-1 do
if (ColorKeyPoints[i].Time <= percentage) and (ColorKeyPoints[i+1].Time >= percentage) then
closestToLeft = ColorKeyPoints[i]
closestToRight = ColorKeyPoints[i+1]
LocalPercentage = (percentage-closestToLeft.Time)/(closestToRight.Time-closestToLeft.Time)
color = closestToLeft.Value:lerp(closestToRight.Value,LocalPercentage)
return color
end
end
warn('Color not found!')
return color
end
“You feed it a percentage (a decimal between 0 and 1), then a list of ColorKeyPoints (UiGradient.Color.Keypoints), and it returns the expected color gradient in-between any given colors.”