HSL to RGB1.
This commit is contained in:
parent
541aff4d13
commit
8241e06099
11
colors.lua
11
colors.lua
|
@ -12,6 +12,10 @@ local colors = {}
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Conversion
|
-- Conversion
|
||||||
|
|
||||||
|
colors.rgb255_to_rgb1 = function (color)
|
||||||
|
return { color[1]/255, color[2]/255, color[3]/255, (color[4] or 255)/255 }
|
||||||
|
end
|
||||||
|
|
||||||
colors.rgb_to_hsl = function (color)
|
colors.rgb_to_hsl = function (color)
|
||||||
-- Error check
|
-- Error check
|
||||||
assert(type(color) == 'table' and type(color[1]) == 'number' and type(color[2]) == 'number' and type(color[3]) == 'number')
|
assert(type(color) == 'table' and type(color[1]) == 'number' and type(color[2]) == 'number' and type(color[3]) == 'number')
|
||||||
|
@ -79,6 +83,10 @@ colors.hsl_to_rgb = function (color)
|
||||||
return { r, g, b }
|
return { r, g, b }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
colors.hsl_to_rgb1 = function (...)
|
||||||
|
return colors.rgb255_to_rgb1(colors.hsl_to_rgb(...))
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Interpolation
|
-- Interpolation
|
||||||
|
|
||||||
|
@ -86,7 +94,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 +159,4 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user