miniqr_simpletest.py
1 import sys 2 import adafruit_miniqr 3 4 # For drawing filled rectangles to the console: 5 out = sys.stdout 6 WHITE = "\x1b[1;47m \x1b[40m" 7 BLACK = " " 8 9 10 def prettyprint_QR(matrix): 11 # white 4-pixel border at top 12 for _ in range(4): 13 for _ in range(matrix.width + 8): 14 out.write(WHITE) 15 print() 16 for y in range(matrix.height): 17 out.write(WHITE * 4) # 4-pixel border to left 18 for x in range(matrix.width): 19 if matrix[x, y]: 20 out.write(BLACK) 21 else: 22 out.write(WHITE) 23 out.write(WHITE * 4) # 4-pixel bporder to right 24 print() 25 # white 4-pixel border at bottom 26 for _ in range(4): 27 for _ in range(matrix.width + 8): 28 out.write(WHITE) 29 print() 30 31 32 qr = adafruit_miniqr.QRCode(qr_type=3, error_correct=adafruit_miniqr.L) 33 qr.add_data(b"https://www.adafruit.com") 34 qr.make() 35 print(qr.matrix) 36 prettyprint_QR(qr.matrix)