Advertisement
Guest User

colors.lua

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. -- Colors
  2. white = 1
  3. orange = 2
  4. magenta = 4
  5. lightBlue = 8
  6. yellow = 16
  7. lime = 32
  8. pink = 64
  9. gray = 128
  10. lightGray = 256
  11. cyan = 512
  12. purple = 1024
  13. blue = 2048
  14. brown = 4096
  15. green = 8192
  16. red = 16384
  17. black = 32768
  18.  
  19. function combine( ... )
  20.     local r = 0
  21.     for n,c in ipairs( { ... } ) do
  22.         r = bit32.bor(r,c)
  23.     end
  24.     return r
  25. end
  26.  
  27. function subtract( colors, ... )
  28.     local r = colors
  29.     for n,c in ipairs( { ... } ) do
  30.         r = bit32.band(r, bit32.bnot(c))
  31.     end
  32.     return r
  33. end
  34.  
  35. function test( colors, color )
  36.     return ((bit32.band(colors, color)) == color)
  37. end
  38.  
  39. function rgb8( r, g, b )
  40.     if type(r) == "number" and g == nil and b == nil then
  41.         return bit32.band( bit32.rshift( r, 16 ), 0xFF ) / 255, bit32.band( bit32.rshift( r, 8 ), 0xFF ) / 255, bit32.band( r, 0xFF ) / 255
  42.     elseif type(r) == "number" and type(g) == "number" and type(b) == "number" then
  43.         return
  44.             bit32.lshift( bit32.band(r * 255, 0xFF), 16 ) +
  45.             bit32.lshift( bit32.band(g * 255, 0xFF), 8 ) +
  46.             bit32.band(b * 255, 0xFF)
  47.     else
  48.         error( "Expected 1 or 3 numbers", 2 )
  49.     end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement