feat: compute a gradient between two hex colors

v2.5
Leon Heidelbach 4 years ago
parent c26d833ae5
commit 2bdae282fa

@ -160,4 +160,28 @@ M.change_hex_lightness = function(hex, percent)
return M.hsl2hex(h, s, l)
end
-- Compute a gradient between two colors
-- @param hex1 The first hex color value
-- @param hex2 The second hex color value
-- @param steps The number of steps to compute
-- @return A table of hex color values
M.compute_gradient = function(hex1, hex2, steps)
local h1, s1, l1 = M.hex2hsl(hex1)
local h2, s2, l2 = M.hex2hsl(hex2)
local h, s, l
local h_step = (h2 - h1) / (steps - 1)
local s_step = (s2 - s1) / (steps - 1)
local l_step = (l2 - l1) / (steps - 1)
local gradient = {}
for i = 0, steps - 1 do
h = h1 + (h_step * i)
s = s1 + (s_step * i)
l = l1 + (l_step * i)
gradient[i + 1] = M.hsl2hex(h, s, l)
end
return gradient
end
return M

Loading…
Cancel
Save