|
11 | 11 |
|
12 | 12 | def draw_QR(matrix):
|
13 | 13 | # how big each pixel is, add 2 blocks on either side
|
14 |
| - BLOCK_SIZE = DISPLAY_W // (qr.matrix.width+4) |
15 |
| - |
| 14 | + BLOCK_SIZE = DISPLAY_W // (matrix.width+4) |
| 15 | + |
16 | 16 | # Center the QR code in the middle of the screen
|
17 |
| - X_OFFSET = (DISPLAY_W - BLOCK_SIZE * qr.matrix.width) // 2 |
18 |
| - Y_OFFSET = (DISPLAY_H - BLOCK_SIZE * qr.matrix.height) // 2 |
19 |
| - |
| 17 | + X_OFFSET = (DISPLAY_W - BLOCK_SIZE * matrix.width) // 2 |
| 18 | + Y_OFFSET = (DISPLAY_H - BLOCK_SIZE * matrix.height) // 2 |
| 19 | + |
20 | 20 | # monochome (2 color) palette
|
21 | 21 | palette = displayio.Palette(2)
|
22 | 22 | palette[0] = 0xFFFFFF
|
23 | 23 | palette[1] = 0x000000
|
24 |
| - |
| 24 | + |
25 | 25 | # bitmap the size of the screen, monochrome (2 colors)
|
26 | 26 | bitmap = displayio.Bitmap(DISPLAY_H, DISPLAY_W, 2)
|
27 |
| - |
| 27 | + |
28 | 28 | # raster the QR code
|
29 | 29 | line = bytearray(DISPLAY_W // 8) # monochrome means 8 pixels per byte
|
30 |
| - for y in range(qr.matrix.height): # each scanline in the height |
31 |
| - for i in range(len(line)): # initialize it to be empty |
| 30 | + for y in range(matrix.height): # each scanline in the height |
| 31 | + for i, _ in enumerate(line): # initialize it to be empty |
32 | 32 | line[i] = 0
|
33 |
| - for x in range(qr.matrix.width): |
34 |
| - if qr.matrix[x, y]: |
| 33 | + for x in range(matrix.width): |
| 34 | + if matrix[x, y]: |
35 | 35 | for b in range(BLOCK_SIZE):
|
36 | 36 | _x = X_OFFSET + x * BLOCK_SIZE + b
|
37 | 37 | line[_x // 8] |= 1 << (7-(_x % 8))
|
38 |
| - |
| 38 | + |
39 | 39 | for b in range(BLOCK_SIZE):
|
40 | 40 | # load this line of data in, as many time as block size
|
| 41 | + #pylint: disable=protected-access |
41 | 42 | bitmap._load_row(Y_OFFSET + y*BLOCK_SIZE+b, line)
|
42 | 43 |
|
43 | 44 | # display the bitmap using our palette
|
44 | 45 | splash = displayio.Group()
|
45 |
| - face = displayio.Sprite(bitmap, pixel_shader=palette, position=(0,0)) |
| 46 | + face = displayio.Sprite(bitmap, pixel_shader=palette, position=(0, 0)) |
46 | 47 | splash.append(face)
|
47 | 48 | board.DISPLAY.show(splash)
|
48 | 49 | board.DISPLAY.wait_for_frame()
|
|
0 commit comments