I created the current code quite a while back in which I provide the starting and ending colors and the number of steps. Returned is a table (an array) of the colors in between the starting and ending colours.
function getColorSteps(starting, ending, steps)
steps = tonumber(steps) or 1
local step = {
(ending[1] - starting[1]) / steps,
(ending[2] - starting[2]) / steps,
(ending[3] - starting[3]) / steps
}
local palette = {
[1] = { unpack(starting) },
[steps] = { unpack(ending) }
}
for i=2, steps-1 do
palette[i] = {
starting[1] + (step[1] * i),
starting[2] + (step[2] * i),
starting[3] + (step[3] * i)
}
end
print( "#palette = " .. #palette )
print( "steps = " .. steps )
for i = 1, #palette do
print(
i ..
". rgb(" ..
table.concat(palette[i], ", ")
.. ")"
)
end
return palette
end
I’d like to have this converted from steps to “progress”. See this example:
s,e = {255,255,255},{0,0,0}
getColorSteps(s,e,0)
> 255, 255, 255, 255
getColorSteps(s,e,0.5)
> 127.5, 127.5, 127.5, 127.5
getColorSteps(s,e,1)
> 0, 0, 0, 0
I’m just not sure how to do it…
Maybe using linear interpolation?
That will however work only if in each of the corresponding color value
i,e[i] > s[i]. So you would probably need to usemath.max(e[0], s[0]) - math.min(e[0], s[0])each time or something similar.And, oh, I would rather use
aandbinstead of start/end; but it may be just my preference.