Hey all.
I used to use this user-created function which I'd picked up from another wow website:
Lua Code:
local function ColorGradient(perc, ...)
if perc >= 1 then
local r, g, b = select(select('#', ...) - 2, ...)
return r, g, b
elseif perc <= 0 then
local r, g, b = ...
return r, g, b
end
local num = select('#', ...) / 3
local segment, relperc = math.modf(perc*(num-1))
local r1, g1, b1, r2, g2, b2 = select((segment*3)+1, ...)
return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
end
I've stripped it to it's bare bones for the sake of speed and simplicity. The three colours which make up it's range are red (0), yellow (50) and green (100). As with the above function, any number passed to the function which is inbetween those numbers will return a colour of the appropriate gradient (ie 25 will return an orangy-red colour):
Lua Code:
local GetPercentageColourGradient = function(percent)
local _, x = mod(percent * 0.02);
return (percent <= 50) and 1 or (percent >= 100) and 0 or (1 - x), (percent >= 50) and 1 or (percent <= 0) and 0 or x, 0;
end
Hope this comes in handy for someone.
Aanson