Skip to content

Commit ff39f81

Browse files
committed
Fixed bug re luminance of 1.0 being turned into 256 and not 255
1 parent 0003ba7 commit ff39f81

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lua/colors.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ function rgb_to_hsl(r, g, b)
103103
end
104104

105105
function rgb_string_to_hsl(rgb)
106-
return rgb_to_hsl(tonumber(rgb:sub(2,3), 16)/256,
107-
tonumber(rgb:sub(4,5), 16)/256,
108-
tonumber(rgb:sub(6,7), 16)/256)
106+
return rgb_to_hsl(tonumber(rgb:sub(2,3), 16)/255,
107+
tonumber(rgb:sub(4,5), 16)/255,
108+
tonumber(rgb:sub(6,7), 16)/255)
109109
end
110110

111111
-----------------------------------------------------------------------------
@@ -116,11 +116,10 @@ end
116116
-----------------------------------------------------------------------------
117117

118118
function Color:to_rgb()
119-
local r, g, b = hsl_to_rgb(self.H, self.S, self.L)
120119
local rgb = {hsl_to_rgb(self.H, self.S, self.L)}
121120
local buffer = "#"
122121
for i,v in ipairs(rgb) do
123-
buffer = buffer..string.format("%02x",math.floor(v*256+0.5))
122+
buffer = buffer..string.format("%02x",math.floor(v*255+0.5))
124123
end
125124
return buffer
126125
end

0 commit comments

Comments
 (0)