-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.py
More file actions
48 lines (41 loc) · 884 Bytes
/
reference.py
File metadata and controls
48 lines (41 loc) · 884 Bytes
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
45
46
47
48
import json
from PIL import Image
import sys
if (len(sys.argv) < 2):
print("Usage: reference.py <image>")
sys.exit(1)
im = Image.open(sys.argv[1])
pix = im.load()
color_mappings = {
'#FF4500': 2,
'#FFA800': 3,
'#FFD635': 4,
'#00A368': 6,
'#7EED56': 8,
'#2450A4': 12,
'#3690EA': 13,
'#51E9F4': 14,
'#811E9F': 18,
'#B44AC0': 19,
'#FF99AA': 23,
'#9C6926': 25,
'#000000': 27,
'#898D90': 29,
'#D4D7D9': 30,
'#FFFFFF': 31
}
orders = []
def rgb_to_hex(rgb):
return '#' + (('%02x%02x%02x' % rgb).upper())
formatted_out = '[\n'
for x in range(1000):
for y in range(1000):
colors = pix[x, y]
if colors[3] == 0:
continue
hex = rgb_to_hex((colors[0], colors[1], colors[2]))
colorid = color_mappings[hex]
orders.append([x, y, colorid])
formatted_out += '[' + str(x) + ', ' + str(y) + ', ' + str(colorid) + '],\n'
formatted_out += ']'
print(formatted_out)