As a Roblox developer, it is currently too hard to perform scalar multiplication and addition on Color3 values. I want to throw a Color3 into a spring or interpolator, and have it produce a reasonable result. Adding in frequency space is a totally reasonable thing to do.
Currently, if I want to interpolate between Color3 values using such methods, I must write additional code to manually handle the interpolation, which is both cumbersome and unnecessary. Since Color3 values already have a Lerp method, they implicitly support the concept of addition and scalar multiplication in a manner consistent with vector spaces:
A + B = Null:Lerp(A:Lerp(B, 1/2), 2)
A * b = Null:Lerp(A, b)
If Roblox is able to address this issue and formally define Color3 values to support these operations, I could directly use Color3 values with existing interpolation tools without having to make a special duplicate.
This would be super helpful, having to type out custom lerp functions for Color3 values is super super annoying. Here’s a temporary solution to lerp color values:
Edit: Alpha is a number between 0 and 1 and controls how much the starting value changes. 1 means it fully changes into the goal value, 0 means it doesn’t change at all, and 0.5 means it is 50% of the way to the end value
local function LerpColor(start, end, alpha)
local R = start.R + (end.R - start.R) * alpha
local G = start.G + (end.G - start.G) * alpha
local R = start.B + (end.B - start.B) * alpha
return Color3.new(R, G, B)
end
local function LerpColor(start, goal, alpha)
local values = {}
for _, v in ipairs({"R", "G", "B"}) do
table.insert(values, start[v] + (goal[v] - start[v]) * alpha)
end
return Color3.new(table.unpack(values))
end
Edit: this is not performant, but you could compact it like this:
local function LerpColor(start, goal, alpha)
return Color3.new(start.R + (goal.R - start.R) * alpha, start.G + (goal.G - start.G) * alpha, start.B + (goal.B - start.B) * alpha)
end
I’m wondering if they could make Color3 use the native vector type just like Vector3. They really just store the same thing.
The problem with color operations, though, is that Color3s are supposed to store unit values but are unclamped and can go past 0-1. Adding two whites and getting (2, 2, 2) might be confusing.
Assuming unclamped Color3s aren’t really intended, they could just add some warning lints.