-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_wordclock_bmp.py
executable file
·57 lines (48 loc) · 1.24 KB
/
generate_wordclock_bmp.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
#!/usr/bin/python3
MATRIX = open("matrix.txt", "r", encoding="utf-8").read().strip()
WORDS = [
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'el-even',
'twel-ve',
'a-quarter',
'half',
'past',
'to',
'dot'
]
MATRIX = MATRIX.strip().upper().replace(' ', '')
WORDS = [w.upper() for w in WORDS]
for idx, word in enumerate(WORDS):
name = word.replace('-', '').upper()
print(f'#define BMP_{name:10s} (bitmap[{idx}])')
print()
print('const unsigned char bitmap[][8] = {')
for word_idx, word in enumerate(WORDS):
name = word.replace('-', '').upper()
def iter_indices():
parts = word.split('-')
idx = 0
for part in parts:
idx = MATRIX.index(part, idx)
assert idx >= 0
for s, c in enumerate(part):
yield idx + s
idx += len(part)
tab = [[0 for x in range(8)] for y in range(8)]
for idx in iter_indices():
x = idx % 9
y = idx // 9
tab[y][x] = 1
t = '{ ' + ', '.join('%3i' % sum(e << (i) for i, e in enumerate(row)) for row in reversed(tab)) + ' }'
print(f' {t}, // {word_idx} -- {name}')
print('};')