Toggle Navigation
Hatchery
Eggs
ballon_captains_badge
ballon_captains.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
ballon_captains.py
raw
Content
import ugfx import math import dialogs import badge EMULATOR = False try: import esp esp.start_sleeping(1) except Exception: EMULATOR = True BADGE_H1 = "Baloon Captains" baloonPic = [ 0xff,0xff,0x07,0xf0,0xff,0xff,0xff,0xff,0x00,0x80,0xff,0xff,0xff,0x3f,0x80,0x00, 0xfe,0xff,0xff,0x0f,0xfc,0x1f,0xf8,0xff,0xff,0x87,0xff,0xff,0xf0,0xff,0xff,0xc3, 0xff,0xff,0xe1,0xff,0xff,0xf1,0xff,0xff,0xc7,0xff,0xff,0xf8,0xff,0xff,0x8f,0xff, 0x7f,0xfc,0xc1,0xff,0x1f,0xff,0x3f,0x7e,0xc0,0xff,0x3f,0xfe,0x1f,0x3e,0xe0,0xff, 0x7f,0xfc,0x1f,0x1f,0xfe,0xff,0x7f,0xfc,0x8f,0x0f,0xff,0xff,0xff,0xf8,0xcf,0x8f, 0xff,0xff,0xff,0xf9,0xc7,0xc7,0xff,0xff,0xff,0xf1,0xe7,0xe3,0xff,0xff,0xff,0xf3, 0xe3,0xe3,0xff,0xff,0xff,0xe3,0xe3,0xf3,0xff,0xff,0xff,0xe3,0xf3,0xf1,0xff,0xff, 0xff,0xe7,0xf1,0xf9,0xff,0xff,0xff,0xc7,0xf1,0xf9,0xff,0xff,0xff,0xc7,0xf9,0xf9, 0xff,0xff,0xff,0xcf,0xf9,0xff,0xff,0xff,0xff,0xcf,0xf9,0xff,0xff,0xff,0xff,0xcf, 0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff, 0xff,0x8f,0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff, 0xff,0xff,0xff,0x9f,0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff,0xff,0x8f, 0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff,0xff,0x8f,0xf8,0xff,0xff,0xff, 0xff,0x8f,0xf9,0xff,0xff,0xff,0xff,0xcf,0xf9,0xff,0xff,0xff,0xff,0xcf,0xf9,0xff, 0xff,0xff,0xff,0xcf,0xf1,0xff,0xff,0xff,0xff,0xc7,0xf3,0xff,0xff,0xff,0xff,0xc7, 0xf3,0xff,0xff,0xff,0xff,0xe7,0xe3,0xff,0xff,0xff,0xff,0xe3,0xe7,0xff,0xff,0xff, 0xff,0xf3,0xc7,0xff,0xff,0xff,0xff,0xf1,0xc7,0xff,0xff,0xff,0xff,0xf1,0x8f,0xff, 0xff,0xff,0xff,0xf8,0x8f,0xff,0xff,0xff,0xff,0xf8,0x1f,0xff,0xff,0xff,0x7f,0xfc, 0x3f,0xfe,0xff,0xff,0x3f,0xfe,0x3f,0xfc,0xff,0xff,0x1f,0xfe,0x7f,0xfc,0xff,0xff, 0x1f,0xff,0xff,0xf0,0xff,0xff,0x87,0xff,0xff,0xe1,0xff,0xff,0xc3,0xff,0xff,0x83, 0xff,0xff,0xe0,0xff,0xff,0x0f,0xff,0x7f,0xf0,0xff,0xff,0x1f,0xfc,0x1f,0xfc,0xff, 0xff,0x7f,0x00,0x00,0xff,0xff,0xff,0xff,0x01,0xc0,0xff,0xff,0xff,0xff,0x1f,0xf0, 0xff,0xff,0xff,0xff,0x07,0xf1,0xff,0xff,0xff,0xff,0x83,0xf1,0xff,0xff,0xff,0xff, 0x81,0xf1,0xff,0xff,0xff,0xff,0x89,0xf3,0xff,0xff,0xff,0xff,0x09,0xf0,0xff,0xff, 0xff,0xff,0x0d,0xf0,0xff,0xff,0xff,0xff,0x09,0xf0,0xff,0xff,0xff,0xff,0xf9,0xff, 0xff,0xff,0xff,0xff,0xf9,0xff,0xff,0xff,0xff,0xff,0xf9,0xff,0xff,0xff,0xff,0xff, 0xf3,0xff,0xff,0xff,0xff,0xff,0xe3,0xff,0xff,0xff,0xff,0xff,0xe7,0xff,0xff,0xff, 0xff,0xff,0xc7,0xff,0xff,0xff,0xff,0xff,0xcf,0xff,0xff,0xff,0xff,0xff,0x9f,0xff, 0xff,0xff,0xff,0xff,0x9f,0xff,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff,0xff,0xff, 0x3f,0xff,0xff,0xff,0xff,0xff,0x7f,0xfe,0xff,0xff,0xff,0xff,0x7f,0xfe,0xff,0xff, 0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfc, 0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff, 0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff, 0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff,0xfe, 0xff,0xff,0xff,0xff,0x7f,0xfe,0xff,0xff,0xff,0xff,0x7f,0xfe,0xff,0xff,0xff,0xff, 0x7f,0xfe,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff, 0xff,0xff,0x3f,0xff,0xff,0xff,0xff,0xff,0x9f,0xff,0xff,0xff,0xff,0xff,0x9f,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0x3f, 0xbf,0x1f,0xff,0xff,0xff,0x9f,0xdf,0x4f,0xff,0xff,0xff,0xe7,0xe7,0x67,0xff,0xff, 0xff,0x07,0x00,0x70,0xff,0xff,0xff,0xf7,0xff,0x77,0xff,0xff,0xff,0xf7,0xff,0x77, 0xff,0xff,0xff,0xf7,0x80,0x77,0xff,0xff,0xff,0xf7,0xff,0x77,0xff,0xff,0xff,0xf7, 0xff,0x77,0xff,0xff,0xff,0xf7,0xff,0x77,0xff,0xff,0xff,0xf7,0xff,0x77,0xff,0xff, 0xff,0xf7,0xff,0x77,0xff,0xff,0xff,0xf7,0xff,0x77,0xff,0xff,0xff,0xf7,0xff,0x37, 0xff,0xff,0xff,0xf7,0xff,0xb7,0xff,0xff,0xff,0xf7,0xff,0xd7,0xff,0xff,0xff,0xf7, 0xff,0xc7,0xff,0xff,0xff,0xf7,0xff,0xe7,0xff,0xff,0xff,0x07,0x00,0xf0,0xff,0xff, ] baloonBorder = [19,16,14,12,11,10,9,8,7,6,5,5,4,4,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,4,4,5,6,6,7,8,9,10,12,13,15,17,21,19,18,17,17,17,17,17,17,17,17,18,18,19,19,20,21,21,22,22,23,23,24,24,24,24,24,24,24,24,24,24,24,23,23,23,22,22,22,21,21,18,16,14,13,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11] def drawBaloon(xOffset, yOffset): def getPixel(x, y): a = x * 48 + y byte = int(a / 8) bit = int(a % 8) if (baloonPic[byte] & (1 << bit)) > 0: return ugfx.WHITE else: return ugfx.BLACK for y in range(0,120): for x in range(0,48): xPix = x + xOffset yPix = y + yOffset if xPix < 296 and xPix > 0 and yPix < 128 and yPix > 0: color = getPixel(y,x) if color == ugfx.BLACK: ugfx.pixel(x + xOffset, y + yOffset, color) # Screen dimensions 296x128 def drawName(): global BADGE_H1, BADGE_NAME, BADGE_RANK leftPadding = -30 topPadding = 20 # Draw the main header headerWidth = ugfx.get_string_width(BADGE_H1, "Roboto-Regular22") headerHeight = 22 headerY = int(128/2 - headerHeight / 2) + topPadding headerX = int(296 / 2 - headerWidth / 2) + leftPadding ugfx.string(headerX, headerY, BADGE_H1, "Roboto-Regular22", ugfx.BLACK) # Draw the name nameWidth = ugfx.get_string_width(BADGE_NAME, "Roboto-Regular18") nameHeight = 18 nameY = int(headerY - nameHeight - 2) nameX = int(296 / 2 - nameWidth / 2) + leftPadding ugfx.string(nameX, nameY, BADGE_NAME, "Roboto-Regular18", ugfx.BLACK) # Draw the title titleWidth = ugfx.get_string_width(BADGE_RANK, "Roboto-Regular12") # titleHeight = 14 titleY = int(headerY + headerHeight + 2) titleX = int(296 / 2 + headerWidth / 2 - titleWidth) + leftPadding ugfx.string(titleX, titleY, BADGE_RANK, "Roboto-Regular12", ugfx.BLACK) def drawSun(): ugfx.fill_circle(0,0,25, ugfx.BLACK) ugfx.thickline(0, 0, int(7*1.2), int(30*1.2), ugfx.BLACK, 2, True) ugfx.thickline(0, 0, int(30*1.2), int(7*1.2), ugfx.BLACK, 2, True) ugfx.thickline(0, 0, int(15*1.2), int(25*1.2), ugfx.BLACK, 2, True) ugfx.thickline(0, 0, int(25*1.2), int(15*1.2), ugfx.BLACK, 2, True) def drawClouds(): x = 60 ugfx.fill_ellipse(x, 0, 50, 20, ugfx.BLACK) x += 70 ugfx.fill_ellipse(x, 0, 30, 15, ugfx.BLACK) x += 70 ugfx.fill_ellipse(x, 0, 40, 25, ugfx.BLACK) def animateBadge(): for x in range(-48, 296-45, 10): ugfx.clear(ugfx.WHITE) # Draw our name batch drawName() # Empty lines after balloon first apperaance for y in range(0, 128): sinCalc = int(math.sin(x * 10 - 0.25 * math.pi) * 12) try: ugfx.line(baloonBorder[y]+x, y + sinCalc, 296, y + sinCalc, ugfx.WHITE) except Exception: ugfx.line(baloonBorder[119] + x, y + sinCalc, 296, y + sinCalc, ugfx.WHITE) # Draw the baloon drawBaloon(x, int(math.sin(x * 10 - 0.25 * math.pi) * 12)) ugfx.flush() def main(): global BADGE_H1, BADGE_NAME, BADGE_RANK ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.flush() BADGE_NAME = badge.nvs_get_str("owner", "name", "") BADGE_RANK = badge.nvs_get_str("owner", "rank", "") if BADGE_RANK == "": BADGE_RANK = dialogs.prompt_text("Please enter rank", "Ballon Aspirant") while True: animateBadge() drawName() esp.start_sleeping(30000) if __name__ == '__main__': main() # def render(text, pushed): # if(pushed): # ugfx.string(100,10,text,"PermanentMarker22",ugfx.WHITE) # else: # ugfx.string(100,10,text,"PermanentMarker22",ugfx.BLACK) # ugfx.flush() # def start_app(pushed): # if(pushed): # import launcher # ugfx.input_init() # ugfx.input_attach(ugfx.JOY_UP, lambda pressed: render('UP', pressed)) # ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: render('DOWN', pressed)) # ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: render('LEFT', pressed)) # ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: render('RIGHT', pressed)) # ugfx.input_attach(ugfx.BTN_A, lambda pressed: render('A', pressed)) # ugfx.input_attach(ugfx.BTN_B, lambda pressed: render('B', pressed)) # ugfx.input_attach(ugfx.BTN_START, start_app) # ugfx.input_attach(ugfx.BTN_SELECT, lambda pressed: render('Select', pressed))