Toggle Navigation
Hatchery
Eggs
angel
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import badge import ugfx import math from angel import pyqrnative angel_name = None def make_qr(name): global angel_name angel_name = name # up to level 27 (125x125px) can be displayed qr = pyqrnative.QRCode(2, pyqrnative.QRErrorCorrectLevel.Q) qr.addData(name) qr.make() return qr def draw_qr(qr, y_offset=0): if qr is None: print("QR is none") return max_x = max_y = qr.getModuleCount() matrix = qr.modules disp_x, disp_y = (296, 128 - y_offset) block_size = math.floor(disp_y/max_y) offset_x = 0 # offset_x = int(disp_x/2) - int(block_size*max_y/2) offset_y = int(disp_y/2) - int(block_size*max_x/2) + y_offset for y, row in enumerate(matrix): for x, col in enumerate(row): if qr.isDark(x, y): ugfx.area(offset_x+x*block_size, offset_y+y*block_size, block_size, block_size, ugfx.BLACK) ugfx.flush() return disp_y if __name__== "__main__": ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.flush() name="angel-{}".format(badge.nvs_get_str("owner", "name", "")) draw_qr(make_qr(name)) ugfx.string(150,10,"ANGEL","PermanentMarker22",ugfx.BLACK) ugfx.string(150,50,angel_name,"PermanentMarker22",ugfx.BLACK)