mirror of
https://github.com/gabehf/base46.git
synced 2026-03-09 23:48:16 -07:00
feat: compute a gradient between two hex colors
This commit is contained in:
parent
c26d833ae5
commit
2bdae282fa
1 changed files with 24 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue