Proposal to add a Color3Curve Instance

As a Roblox developer, it is currently too hard to gradually change the color of a BasePart into more than one color, as the most convenient way to do so is by using a ColorSequence Data Type which requires the use of a function as shown below in order to interpolate between each Color3 value

local function colorSequenceLerp(colorSequence: ColorSequence, time: number): Color3
	if time == 0 then return colorSequence.Keypoints[1].Value end
	if time == 1 then return colorSequence.Keypoints[#colorSequence.Keypoints].Value end

	for i = 1, #colorSequence.Keypoints - 1 do
		local currentKeypoint = colorSequence.Keypoints[i]
		local nextKeypoint = colorSequence.Keypoints[i + 1]

		if time >= currentKeypoint.Time and time < nextKeypoint.Time then
			return currentKeypoint.Value:Lerp(nextKeypoint.Value, (time - currentKeypoint.Time) / (nextKeypoint.Time - currentKeypoint.Time))
		end
	end
end

And while this does achieve the desired effect, this does have some drawbacks namely:

  • It requires good math knowledge if you wish to use a non-linear interpolation method
  • You must remember to either write and store the function somewhere (ideally inside a ModuleScript), use a ModuleScript provided by a player than includes this function, or copy the function from a free resource or tutorial
  • The function will take up a small bit of memory (Admittedly if you’re storing it in a module, this isn’t that much of a problem although it will still take up a small bit of memory)
  • Most of the calculations are done using Luau, and while Luau is fast, using a function like FloatCurve:GetValueAtTime() has the advantage of calculating in C

If this issue is addressed, it would improve my development experience because it will be much simpler to create a custom health Gui that gradually shifts colors depending on how hurt a Humanoid is for example

Do you agree with my proposal?
  • Yes
  • No
  • Indifferent

0 voters

1 Like