Skip to content

Commit

Permalink
Fixed bug re luminance of 1.0 being turned into 256 and not 255
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Feb 25, 2010
1 parent 0003ba7 commit ff39f81
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lua/colors.lua
Expand Up @@ -103,9 +103,9 @@ function rgb_to_hsl(r, g, b)
end

function rgb_string_to_hsl(rgb)
return rgb_to_hsl(tonumber(rgb:sub(2,3), 16)/256,
tonumber(rgb:sub(4,5), 16)/256,
tonumber(rgb:sub(6,7), 16)/256)
return rgb_to_hsl(tonumber(rgb:sub(2,3), 16)/255,
tonumber(rgb:sub(4,5), 16)/255,
tonumber(rgb:sub(6,7), 16)/255)
end

-----------------------------------------------------------------------------
Expand All @@ -116,11 +116,10 @@ end
-----------------------------------------------------------------------------

function Color:to_rgb()
local r, g, b = hsl_to_rgb(self.H, self.S, self.L)
local rgb = {hsl_to_rgb(self.H, self.S, self.L)}
local buffer = "#"
for i,v in ipairs(rgb) do
buffer = buffer..string.format("%02x",math.floor(v*256+0.5))
buffer = buffer..string.format("%02x",math.floor(v*255+0.5))
end
return buffer
end
Expand Down

0 comments on commit ff39f81

Please sign in to comment.