-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (34 loc) · 1.18 KB
/
main.py
File metadata and controls
48 lines (34 loc) · 1.18 KB
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
# --------------------------------------------------
# ! DOSEN'T WORK WITH PYPY, ONLY WORKS WITH CPYTHON
# due to some issues with printing unicode chars
# --------------------------------------------------
import qrcode
import numpy as np
import sys
# generate qr code as binary matrix
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=1,
border=4,
)
qr.add_data(sys.argv[1])
qr.make(fit=True)
qr = qr.make_image(fill_color="black", back_color="white")
qr = np.array(qr)
# if height of qr code is odd, append one row of zeros
# since each block character is 2x1 (height x width)
if (qr.shape[0]%2 == 1):
qr = np.vstack((qr, np.zeros((1, qr.shape[1]), dtype=bool)))
# print the qr code using block unicode chars ('▄','█','▀',' ')
for i in range(0, qr.shape[0], 2):
for j in range(qr.shape[1]):
if qr[i,j] == True and qr[i+1,j] == True:
print("█", end="")
elif qr[i,j] == True and qr[i+1,j] == False:
print("▀", end="")
elif qr[i,j] == False and qr[i+1,j] == True:
print("▄", end="")
else:
print(" ", end="")
print("\n", end="")