-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolors.lua
More file actions
44 lines (38 loc) · 1.04 KB
/
colors.lua
File metadata and controls
44 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local expect = require "cc.expect"
local colors = {
white = 0,
orange = 1,
magenta = 2,
lightBlue = 3,
yellow = 4,
lime = 5,
pink = 6,
gray = 7,
lightGray = 8,
cyan = 9,
purple = 10,
blue = 11,
brown = 12,
green = 13,
red = 14,
black = 15
}
-- These are not intended to work properly, as bundled wire does not use colors in Phoenix.
function colors.combine(...) return math.max(...) end
function colors.subtract(...) return math.min(...) end
function colors.test(a, b) return a == b end
function colors.packRGB(r, g, b)
expect(1, r, "number")
expect(2, g, "number")
expect(3, b, "number")
return bit32.bor(bit32.lshift(r * 255, 16), bit32.lshift(g * 255, 8), b * 255)
end
function colors.unpackRGB(rgb)
expect(1, rgb, "number")
return bit32.band(bit32.rshift(rgb, 16), 0xFF) / 255, bit32.band(bit32.rshift(rgb, 8), 0xFF) / 255, bit32.band(rgb, 0xFF) / 255
end
function colors.toBlit(color)
expect(1, color, "number")
return ("%x"):format(color)
end
return colors