-
Notifications
You must be signed in to change notification settings - Fork 0
/
genmaze.py
38 lines (27 loc) · 794 Bytes
/
genmaze.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
# take in a PNG image of a maze (from dadaelus + some modification), and convert into a bitmap
import numpy as np
from bitarray import bitarray
from PIL import Image
import sys
np.set_printoptions(threshold=np.inf)
im = Image.open(sys.argv[1])
data = np.asarray(im)
width = len(data)
height = len(data[0])
bitmap = np.ones((width//2,height//2), dtype=int)
for i in range(0, width, 2):
for j in range(0, height, 2):
x = i // 2
y = j // 2
if (list(data[i,j]) == list([255,255,255])):
bitmap[x,y] = 0
bitstring = ""
for x in bitmap.flatten():
if x == 1:
bitstring += '1'
else:
bitstring += '0'
bits = bitarray(bitstring)
with open(sys.argv[1].split(".")[0] + ".bin", 'wb') as fh:
bits.tofile(fh)
print("width: %d, height: %d" %(width//2, height//2))