I need to interpolate between two colors, but find the specific value at a specified time.
I will not use RGB for this, as that gives brown in between most colors. Instead I am using HSV, which is great for rotating between colors. (RGB: Color Cube. HSV: Color Wheel)
My current code:
local ColorScaleStatic = {}
ColorScaleStatic.__index = ColorScaleStatic
function ColorScaleStatic.new (PointA:Color3,PointB:Color3): ColorScale
local ColorScale = {}
setmetatable(ColorScale,ColorScaleStatic)
ColorScale.HueA,ColorScale.SatA,ColorScale.ValA = PointA:ToHSV()
ColorScale.HueB,ColorScale.SatB,ColorScale.ValB = PointB:ToHSV()
return ColorScale
end
function ColorScaleStatic:AtScale (Scale:number):Color3
return Color3.fromHSV(
self.HueA+(self.HueB-self.HueA)*Scale,
self.SatA+(self.SatB-self.SatA)*Scale,
self.ValA+(self.ValB-self.ValA)*Scale
)
end
function ColorScaleStatic:TestTween (Frame:Frame,Time:number)
for i=0,1,0.01 do
Frame.BackgroundColor3 = self:AtScale(i)
wait(Time/100)
end
end
export type ColorScale = typeof (ColorScaleStatic.new())
return ColorScaleStatic
The only issue I am currently having, is that this goes (Starting at red, going to green) towards pink and blue, instead of towards orange and yellow.
Basically: I want to go the LEFT around the color wheel, not right.
Any help is appreciated!