I put my CIELUV color interpolator on Gist a few weeks ago. I improved it last night by adding some sig figs and making it less slow, so just figured I’d make a thread about it.
If you don’t know what CIELUV is (you probably don’t and that’s ok), it’s a perceptually uniform and additive color space. In other words, it’s really good at representing color transitions on LCD screens for human eyes.
My code works by taking two colors in RGB, transforming them into D65 sRGB, transforming those into XYZ coordinates, transforming those into LUV, lerping in LUV space, then reversing the process. It’s not cheap, but it’s fast enough for most cases.
Example code:
local colorA = Color3.new(1,0,0)
local colorB = Color3.new(0,1,0)
local LerpAB = LerpCIELUV(colorA, colorB)
for t = 0, 1, 1/60 do
thing.BackgroundColor3 = LerpAB(t)
Heartbeat:wait()
end
As I was writing this post about how maybe there should be objects to do this so you aren’t going back and forth every lerp, I realized you already have this by returning a function to do the lerp as opposed to simply giving out a color3 after receiving two color3 and a number.
It looks excellent!
EDIT: it makes me want to create a black body color module.
Thanks. A blackbody color module sounds neat. Keep in mind that the sRGB->XYZ conversion in my module is just a farce to arrive at the L component faster, so that code probably shouldn’t be used for that purpose. Actual sRGB->XYZ conversion is this
local x, y, z = 0.4123955889674142161*r + 0.3575834307637148171*g + 0.1804926473817015735*b,
0.2125862307855955516*r + 0.7151703037034108499*g + 0.0722004986433362268*b,
0.0192972154917469448*r + 0.1191838645808485318*g + 0.9504971251315797660*b
hit the wrong reply button, I guess tagging works @NWSpacek
In my case I would not necessarily have to convert sRGB → XYZ because the expected input is a temperature or alpha (EDIT: and maybe a Duv value for CCT): I plan on grabbing the color from the Planckian locus and give it to the user as a Color3.