Add colours.rgb8(r, g, b)/colours.rgb8(hex)

This commit is contained in:
Lignum 2017-05-07 00:13:36 +02:00
parent a9e7acbec5
commit 1cc403191f
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
1 changed files with 15 additions and 5 deletions

View File

@ -25,13 +25,23 @@ function combine( ... )
end
function subtract( colors, ... )
local r = colors
for n,c in ipairs( { ... } ) do
r = bit32.band(r, bit32.bnot(c))
end
return r
local r = colors
for n,c in ipairs( { ... } ) do
r = bit32.band(r, bit32.bnot(c))
end
return r
end
function test( colors, color )
return ((bit32.band(colors, color)) == color)
end
function rgb8( r, g, b )
if type(r) == "number" and g == nil and b == nil then
return bit32.band( bit32.rshift( r, 16 ), 0xFF ) / 255, bit32.band( bit32.rshift( r, 8 ), 0xFF ) / 255, bit32.band( r, 0xFF ) / 255
elseif type(r) == "number" and type(g) == "number" and type(b) == "number" then
return r / 255, g / 255, b / 255
else
return nil
end
end