1
0

Fixed bug

This commit is contained in:
Jon Michael Aanes 2018-10-22 13:14:00 +02:00
parent 541aff4d13
commit 96aec93fc5

View File

@ -22,10 +22,9 @@ colors.rgb_to_hsl = function (color)
local b = (color[3] == 255 and 1 or color[3]/256) local b = (color[3] == 255 and 1 or color[3]/256)
local max, min = math.max(r, g, b), math.min(r, g, b) local max, min = math.max(r, g, b), math.min(r, g, b)
if min == max then return { 0, 0, (max+min)/2 } end
local h, s, l = (max+min)/2, (max+min)/2, (max+min)/2 local h, s, l = (max+min)/2, (max+min)/2, (max+min)/2
if min == max then
return {0, 0, l}
end
local d = max - min local d = max - min
s = l > 0.5 and d / (2 - max - min) or d / (max + min) s = l > 0.5 and d / (2 - max - min) or d / (max + min)
@ -86,7 +85,7 @@ colors.interpolate_rgb = function (c1, c2, t)
assert(type(c1) == 'table' and type(c1[1]) == 'number' and type(c1[2]) == 'number' and type(c1[3]) == 'number' and (type(c1[4]) == 'number' or c1[4] == nil)) assert(type(c1) == 'table' and type(c1[1]) == 'number' and type(c1[2]) == 'number' and type(c1[3]) == 'number' and (type(c1[4]) == 'number' or c1[4] == nil))
assert(type(c2) == 'table' and type(c2[1]) == 'number' and type(c2[2]) == 'number' and type(c2[3]) == 'number' and (type(c2[4]) == 'number' or c2[4] == nil)) assert(type(c2) == 'table' and type(c2[1]) == 'number' and type(c2[2]) == 'number' and type(c2[3]) == 'number' and (type(c2[4]) == 'number' or c2[4] == nil))
assert(type(t) == 'number') assert(type(t) == 'number')
-- --
local alpha = nil local alpha = nil
if c1[4] or c2[4] then alpha = (c1[4] or 255) + ((c2[4] or 255)-(c1[4] or 255))*t end if c1[4] or c2[4] then alpha = (c1[4] or 255) + ((c2[4] or 255)-(c1[4] or 255))*t end
return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t, alpha } return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t, alpha }
@ -151,3 +150,4 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
return colors return colors