-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrgb_maps.py
executable file
·61 lines (48 loc) · 1.12 KB
/
rgb_maps.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/python
"""Generates RGB maps."""
import sys
WHITE = 0b111
YELLOW = 0b110
CYAN = 0b011
MAGENTA = 0b101
RED = 0b100
GREEN = 0b010
BLUE = 0b001
BLACK = 0b000
def calc_bit(fg, bg, p):
return {
(1, 1): 0xFF,
(1, 0): p,
(0, 1): ~p,
(0, 0): 0
}[(fg, bg)]
def calc_rgb(fg, bg):
def inner(p):
r = calc_bit((fg >> 2) & 1, (bg >> 2) & 1, p)
g = calc_bit((fg >> 1) & 1, (bg >> 1) & 1, p)
b = calc_bit((fg >> 0) & 1, (bg >> 0) & 1, p)
return (r, g, b)
return inner
def white_on_blue(p):
return (p, p, 0xFF)
def white_on_black(p):
return (p, p, p)
def blue_on_white(p):
return (~p, ~p, 0xFF)
def green_on_black(p):
return (0, p, 0)
def generate(gen_fun):
sys.stdout.write("[\n")
for p in range(0, 256):
r, g, b = gen_fun(p)
word = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0)
sys.stdout.write("0x{:06x}, ".format(word))
if ((p + 1) % 8) == 0:
sys.stdout.write("\n")
sys.stdout.write("],\n")
sys.stdout.write("[\n")
for fg in range(0, 8):
for bg in range(0, 8):
sys.stdout.write("// FG RGB = {:03b}, BG RGB = {:03b}\n".format(fg, bg))
generate(calc_rgb(fg, bg))
sys.stdout.write("];")