-
Notifications
You must be signed in to change notification settings - Fork 2
/
sprites.py
87 lines (72 loc) · 2.95 KB
/
sprites.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# flake8: noqa
import numpy as np
from PIL import Image
# The data comes from the original ST listings.
# fmt: off
oblique_mirror_data = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1,0,3,0,4,0,
8,0,28,0,54,0,107,0,210,0,420,0,840,0,1680,0,
3360,0,6720,0,13440,0,26880,0,53760,0,41984,0,18432,0,36864,0,
9,0,18,0,37,0,75,0,150,0,300,0,600,0,1200,0,
2400,0,4800,0,9600,0,19200,0,54784,0,27648,0,14336,0,4096,0,
8192,0,49152,0,32768,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
]
reverse_oblique_mirror_data = [
4096,0,14336,0,27648,0,54784,0,19200,0,9600,0,4800,0,2400,0,
1200,0,600,0,300,0,150,0,75,0,37,0,18,0,9,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,32768,0,49152,0,8192,0,
4,0,3,0,1,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
36864,0,18432,0,41984,0,53760,0,26880,0,13440,0,6720,0,3360,0,
1680,0,840,0,420,0,210,0,107,0,54,0,28,0,8,0,
]
mirror_ball_data = [
0,0,15,0,127,0,507,0,1022,0,2013,0,4086,0,8063,0,
8181,0,15839,0,14330,0,16247,0,32221,0,30583,0,32221,0,32630,0,
0,0,61440,0,65024,0,24448,0,59840,0,21216,0,41072,0,17080,0,
43288,0,20604,0,43964,0,17748,0,43710,0,21870,0,43710,0,30582,0,
32221,0,30582,0,32221,0,32631,0,15325,0,16383,0,16255,0,8191,0,
7645,0,4095,0,1911,0,989,0,503,0,127,0,15,0,0,0,
40414,0,30582,0,56798,0,30590,0,56828,0,65532,0,32636,0,65528,0,
56792,0,65392,0,30688,0,56768,0,30592,0,65024,0,61440,0,0,0,
]
matt_black_ball_data = [
0,0,15,0,127,0,511,0,1023,0,2047,0,4095,0,8191,0,
8191,0,16383,0,16383,0,16383,0,32767,0,32767,0,32767,0,32767,0,
0,0,61440,0,65024,0,65408,0,65472,0,65504,0,65520,0,65528,0,
65528,0,65532,0,65532,0,65532,0,65534,0,65534,0,65534,0,65534,0,
32767,0,32767,0,32767,0,32767,0,16383,0,16383,0,16383,0,8191,0,
8191,0,4095,0,2047,0,1023,0,511,0,127,0,15,0,0,0,
65534,0,65534,0,65534,0,65534,0,65532,0,65532,0,65532,0,65528,0,
65528,0,65520,0,65504,0,65472,0,65408,0,65024,0,61440,0,0,0,
]
# fmt: on
def convert(raw_data):
d = np.array(raw_data, dtype=">u2") # original is big endian
quadrants = []
for a in np.split(d, 4):
a = a[::2].copy() # remove background (all 0)
a = a.view(np.uint8) # convert to bytes
a = np.unpackbits(a) # convert to bits
a = a.astype(np.uint8).reshape(16, 16)
a[a == 0] = 255
a[a == 1] = 0
quadrants.append(a)
arr = np.empty((32, 32), dtype=np.uint8)
arr[0:16, 0:16] = quadrants[0]
arr[0:16, 16:32] = quadrants[1]
arr[16:32, 0:16] = quadrants[2]
arr[16:32, 16:32] = quadrants[3]
i = Image.fromarray(arr, mode="L")
return i
i = convert(oblique_mirror_data)
i.save("sprites/oblique_mirror.png", "PNG")
i = convert(reverse_oblique_mirror_data)
i.save("sprites/reverse_oblique_mirror.png", "PNG")
i = convert(mirror_ball_data)
i.save("sprites/mirror_ball.png", "PNG")
i = convert(matt_black_ball_data)
i.save("sprites/matt_black_ball.png", "PNG")