Have no idea how to interpolate from one color to another.
4 replies, posted
Hey, I'm trying to create a timer for my gamemode, and I want the timer color to go from green (when the timer has just begun), to red (when it is nearing completion). I've tried messing around with HSVToColor, but I can't wrap my head around it at all. All I want is a linear interpolation from one color to another, unless you know how Bezier works, then please let me know.
I don't have a solution, but I do have a tip:
Don't try and do the math necessary for this inside the Color() function. Use parented variables in your think function, or local variables in your paint function, instead.
Assuming this is being called inside of a Paint or Think function already just use Lerp to lerp the Hue value (stored in a variable of course) to the target value (3rd argument). When you want to go back and forth simply set the target back to the hue value corresponding to the color you wish to transition to.
function InterpolateColor(startcolor, finishcolor, maxvalue, currentvalue)
local hsvStart = ColorToHSV(finishcolor)
local hsvFinish = ColorToHSV(startcolor)
local hueLerp = Lerp(normalize(0, maxvalue, currentvalue), hsvStart, hsvFinish)
local finalHsv = HSVToColor(hueLerp, 1, 1)
return finalHsv
end
This is what I got now. I flipped the start and finish color because it ended up reversing the way I wanted it. Thank you both!
Sorry, you need to Log In to post a reply to this thread.