From 1cc403191f17543c6df4089d2f508b1f496c5c63 Mon Sep 17 00:00:00 2001 From: Lignum Date: Sun, 7 May 2017 00:13:36 +0200 Subject: [PATCH] Add colours.rgb8(r, g, b)/colours.rgb8(hex) --- .../assets/computercraft/lua/rom/apis/colors | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/colors b/src/main/resources/assets/computercraft/lua/rom/apis/colors index 94bc3c2a5..80edbe32a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/colors +++ b/src/main/resources/assets/computercraft/lua/rom/apis/colors @@ -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 \ No newline at end of file