mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
rgb to hsl
This commit is contained in:
parent
7e467b279f
commit
e9687d763f
19
colour.lua
19
colour.lua
@ -108,7 +108,24 @@ function colour.hsl_to_rgb(h, s, l)
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
--todo: rgb to hsl
|
||||
--convert rgb to hsl
|
||||
function colour.rgb_to_hsl(r, g, b)
|
||||
local max, min = math.max(r, g, b), math.min(r, g, b)
|
||||
if max == min then return 0, 0, min end
|
||||
|
||||
local l, d = max + min, max - min
|
||||
local s, h = d / (l > 1 and (2 - l) or l)
|
||||
l = l / 2
|
||||
if max == r then
|
||||
h = (g - b) / d
|
||||
if g < b then h = h + 6 end
|
||||
elseif max == g then
|
||||
h = (b - r) / d + 2
|
||||
else
|
||||
h = (r - g) / d + 4
|
||||
end
|
||||
return h / 6, s, l
|
||||
end
|
||||
|
||||
--todo: hsv, other colour spaces
|
||||
--todo: oklab https://bottosson.github.io/posts/oklab/
|
||||
|
Loading…
Reference in New Issue
Block a user