def top_left_logo(): ugfx.clear(ugfx.html_color(0x000000)) try: logo = http.get("https://i.imgur.com/5HXmXBU.png").raise_for_status().content ugfx.display_image(0, 5, bytearray(logo)) except: pass
def draw_badge(): style.set_enabled([ugfx.WHITE, ugfx.html_color(0x800080), ugfx.html_color(0x800080), ugfx.html_color(0x800080)]) style.set_background(ugfx.html_color(0x800080)) ugfx.clear(ugfx.html_color(0x800080)) ugfx.set_default_style(style) # Logo stuff ugfx.display_image( int((ugfx.width() - logo_width) / 2), int((ugfx.height() - logo_height) / 2), logo_path ) # Draw for people to see ugfx.orientation(90) # Draw introduction ugfx.set_default_font(ugfx.FONT_TITLE) ugfx.Label(0, ugfx.height() - name_height - intro_height, ugfx.width(), intro_height, intro_text, justification=ugfx.Label.CENTER) # Process name name_setting = name("Set your name in the settings app") if len(name_setting) <= max_name: ugfx.set_default_font(ugfx.FONT_NAME) else: ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) # Draw name ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, name_setting, justification=ugfx.Label.CENTER) # Draw for wearer to see ugfx.orientation(270) ugfx.set_default_font(ugfx.FONT_SMALL) status = ugfx.Label(0, ugfx.height() - status_height, ugfx.width(), status_height, "", justification=ugfx.Label.LEFT)
def show_start(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(2000) loop_notice("Please insert a coin to\nlearn your personal lucky melody.", "main.gif") show_next_step()
def loading_screen(): logo = 'praise_horse_worship_melon/loading.gif' ugfx.area(0,0,ugfx.width(),ugfx.height(),0xFFFF) ugfx.display_image(2,2,logo) ugfx.set_default_font(ugfx.FONT_SMALL) ugfx.text(60, 145, "Praise Horse (A)", ugfx.GREY) ugfx.text(55, 305, "Worship Melon (B)", ugfx.GREY)
def drawLogo(offset=0, max_height=ugfx.height(), center=True): global cfg_logo, default_logo try: info = badge.png_info(cfg_logo) except: try: cfg_logo = default_logo info = badge.png_info(cfg_logo) except: return 0 width = info[0] height = info[1] if width > ugfx.width(): print("Image too large (x)") return if height > ugfx.height(): print("Image too large (y)") x = int((ugfx.width() - width) / 2) if center: if max_height - height < 0: print("Not enough space for logo", max_height, height) return 0 y = int((max_height - height) / 2) + offset else: y = offset try: #badge.png(x,y,cfg_logo) ugfx.display_image(x, y, cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def download_avatar(): avatar_url = db.get("avatar_url", "") if avatar_url: if (avatar_url.endswith(".png") or avatar_url.startswith("http")): try: image = http.get(avatar_url).raise_for_status().content ugfx.orientation(90) ugfx.display_image(0, 0, bytearray(image)) #f = open(avatar_file_name, 'w') #f.write(image) #f.close() #ugfx.display_image(0,0,bytearray(image)) except: ugfx.clear(ugfx.html_color(0x000000)) ugfx.orientation(270) ugfx.text(3, 65, "Couldn't download the avatar.", ugfx.RED) return False else: ugfx.clear(ugfx.html_color(0x000000)) ugfx.orientation(270) ugfx.text(3, 65, "Invalid avatar url.", ugfx.RED) return False else: ugfx.clear(ugfx.html_color(0x000000)) ugfx.orientation(270) ugfx.text(3, 65, "No avatar url.", ugfx.RED) return True
def loading_screen(): logo = 'lobstervision/lobsterpictures.gif' ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0xFFFF) ugfx.display_image(0, 50, logo) ugfx.set_default_font(ugfx.FONT_SMALL) ugfx.text(15, 305, "lobstervision.tv/emf2018", ugfx.GREY) display_loading()
def init_screen(orientation): # initialize screen ugfx.clear() ugfx.orientation(orientation) ugfx.backlight(50) # show initial screen # photo credit: https://www.flickr.com/photos/remedy451/8061918891 ugfx.display_image(0, 0, 'trains/splash.gif', 90)
def display_logo(): ugfx.clear(ugfx.BLACK) ugfx.string(280, 228, 'v{}'.format(get_version()), 'IBMPlexSans_Regular12', ugfx.WHITE) ugfx.display_image(40, 70, bytearray(open('ibm_logo.gif', 'rb').read()), 2, 300) ugfx.string_box(0, 140, ugfx.width(), 50, 'Developer Day 2018', 'IBMPlexSans_Regular22', ugfx.HTML2COLOR(0x01d7dd), ugfx.justifyCenter) gc.collect()
def nick_screen(container_handle): if not container_handle: container_handle = ugfx.Container(0, 0, 320, 240) container_handle.area(0, 0, 320, 240, ugfx.html_color(pyb.rng()%0xffffff)) ugfx.display_image(0, 0, "apps/sponsors/splash3.gif") container_handle.show() return container_handle
def draw_background(self, colour): logo = 'apps/emf_hub_mon/emf_hub_mon.gif' ugfx.area(0, 0, ugfx.width(), ugfx.height(), colour) ugfx.area(0, 0, ugfx.width(), 25, ugfx.GREY) ugfx.display_image(10, 30, logo)
def display(): logo = 'apps/nexmo~messages/nexmo_logo.gif' ugfx.area(0,0,ugfx.width(),ugfx.height(),0xFFFF) ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) ugfx.text(20,20,"My Number is...",ugfx.BLACK) ugfx.text(20,130,"Powered By, ",ugfx.GREY) ugfx.display_image(15,150,logo) ugfx.set_default_font(ugfx.FONT_TITLE) ugfx.text(40,75,mynumber+" ",ugfx.BLUE)
def show_melody(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) dialogs.notice("You will now hear your personal lucky melody.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") play_melody() show_next_step()
def show_std(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") dialogs.prompt_boolean("Did you have STDs?", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") with dialogs.WaitingMessage("Please wait a moment.", title="Processing..."): sleep.sleep_ms(6000) show_next_step()
def intro(): global foreground, background ugfx.clear(background) ugfx.display_image(0, 0, '/lib/matrix/neo.png') ugfx.string(20, 05, "Entering", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(30, 40, "the", "PermanentMarker22", ugfx.WHITE) ugfx.string(20, 80, "MATRIX", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(185, 95, "Anyway...", "PermanentMarker22", ugfx.WHITE) ugfx.flush()
def display_help(): global start_time ugfx.display_image(0, 0, "shared/sequencer_info.png") wait_until = time.ticks_ms() + 5000 while time.ticks_ms() < wait_until: time.sleep(0.1) if Buttons.is_pressed(Buttons.BTN_A) or Buttons.is_pressed(Buttons.BTN_B) or Buttons.is_pressed(Buttons.BTN_Menu): break start_time = time.ticks_ms()
def loop(): while True: if badge.eink_busy(): send_random_colors() else: ugfx.display_image(0,0, '/lib/dancin_disco_dave/trimmed_image_{}.png'.format(choice(idle))) ugfx.flush() #slows everything down and also allows processing input time.sleep(0.1)
def doScroll(): global yPos, maxHeight, logo # Blank previous logo location ugfx.area(0, yPos, ugfx.width(), yPos + logo_height, 0) # Move up and wrap yPos -= 20 if (yPos <= -logo_height): yPos = maxHeight # Draw logo ugfx.display_image(int((ugfx.width() - logo_width) / 2), int(yPos), logo)
def render_splash_screen(): ugfx.clear(ugfx.html_color(0x000000)) try: logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content ugfx.display_image( int((ugfx.width() - 164)/2), 20, bytearray(logo)) except: pass ugfx.text(160, 100, "TILDR", ugfx.WHITE) ugfx.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE) ugfx.text(45, 300, "Press A to begin", ugfx.WHITE)
def show_repeat(): dialogs.notice("Please repeat your personal lucky melody.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(3000) dialogs.notice("PLEASE REPEAT YOUR PERSONAL LUCKY MELODY.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(4000) dialogs.notice("Please repeat your personal lucky melody a bit louder.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(4000) dialogs.notice( "Unfortunately, this tone\nwas wrong. Please repeat\nyour personal lucky melody\nonce again.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(6000) dialogs.notice( "This lucky melody will help you in every situation.\nMany thanks.", title=APP_TITLE) show_next_step()
def load_avatar(): #Load the avatar from the local storage try: f = open(avatar_file_name, 'r') avatar_file = f.read() ugfx.orientation(90) ugfx.display_image(0, 0, bytearray(avatar_file)) f.close() return True except: ugfx.clear(ugfx.html_color(0x000000)) ugfx.orientation(270) ugfx.text(3, 65, "No local avatar.", ugfx.RED) return False
def display_image(): gc.collect() global selectedProject, selectedCamera, filename display_loading() endpoint = 'images/project/%d/camera/%d/%s' % \ (selectedProject, selectedCamera, filename) try: headers = {'Authorization': 'Basic ' + ACCESS_KEY} url = IMAGE_PROXY + endpoint get(url, headers=headers).raise_for_status().download_to(PHOTO_FILE) except OSError as e: display_error('Unable to download image %s' % e) return utime.sleep_ms(200) ugfx.display_image(0, 0, PHOTO_FILE) display_datetime()
def loop_notice(text, image, is_numpad=False, interval=4000): next_tick = 0 while True: if time.ticks_ms() > next_tick: dialogs.notice(text, title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % image) next_tick = time.ticks_ms() + interval if is_numpad: if is_pressed(Buttons.BTN_1) or is_pressed(Buttons.BTN_2) or is_pressed(Buttons.BTN_3) or is_pressed(Buttons.BTN_4) or is_pressed(Buttons.BTN_5) or is_pressed(Buttons.BTN_6) or is_pressed(Buttons.BTN_7) or is_pressed(Buttons.BTN_8) or is_pressed(Buttons.BTN_9): break else: if is_pressed(Buttons.BTN_A): break sleep.wfi()
def messageCentered(message, firstLineTitle=True, png=None): try: font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" color = ugfx.BLACK ugfx.clear(ugfx.WHITE) parts = message.split("\n") lines = [] font = font1 for part in parts: if len(part) < 1: lines.append("") else: lines.extend(lineSplit(part, ugfx.width(), font)) if firstLineTitle: font = font2 offset_y = int(ugfx.height() / 2) #Half of the screen height offset_y -= 9 #Height of the first line divided by 2 if firstLineTitle: offset_y -= 6 * len(lines) - 1 #Height of font1 divided by 2 else: offset_y -= 9 * len(lines) - 1 #Height of font2 divided by 2 if png != None: try: img_info = badge.png_info(png) offset_y -= int(img_info[1] / 2) + 4 img_x = int((ugfx.width() - img_info[0]) / 2) ugfx.display_image(img_x, offset_y, png) offset_y += img_info[1] + 8 except: pass lineCentered(offset_y, lines[0], font1, color) offset_y += 18 for i in range(len(lines) - 1): if not firstLineTitle: lineCentered(offset_y, lines[i + 1], font1, color) offset_y += 18 else: lineCentered(offset_y, lines[i + 1], font2, color) offset_y += 12 ugfx.flush() except: print("!!! Exception in easydraw.messageCentered !!!")
def show_card(): url = database.get(DB_KEY_CARD) if url: try: with dialogs.WaitingMessage("Loading data...", title=APP_TITLE): image = http.get(url).raise_for_status().content ugfx.display_image(0, 0, bytearray(image)) while ((not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu))): sleep.wfi() except Exception as ex: dialogs.notice(repr(ex), title="%s - Download failed" % APP_TITLE) else: dialogs.notice("Please answer the questions first", title=APP_TITLE) show_menu()
def get_strip(): global strip LED(LED.RED).on() try: strip_json = http.get("https://xkcd.com/info.0.json").raise_for_status().content strip = ujson.loads(strip_json) except: print('couldn't fetch strip json') LED(LED.RED).off() LED(LED.GREEN).on() try: strip_img = http.get(strip['img']).raise_for_status().content ugfx.display_image(0,0,bytearray(strip_img)) except: print('couldn't fetch strip image') LED(LED.GREEN).off()
def screen(state): window = ugfx.Container(0, 0, 240, 320) window.show() try: # logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content ugfx.display_image( int((ugfx.width() - 164)/2), 20, "tildr/biglogo.png") except: pass window.text(160, 100, "TILDR", ugfx.WHITE) window.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE) window.text(45, 300, "Press A to begin", ugfx.WHITE) state['ui'].append(window)
def show_screen(type=None): if type == "horse": img = "praise_horse_worship_melon/horse.gif" color = ugfx.RED text = "HORSE!" elif type == "melon": img = "praise_horse_worship_melon/melon.gif" color = ugfx.BLUE text = "MELON!" else: return ugfx.area(0,0,ugfx.width(),ugfx.height(), color) ugfx.display_image(0, 0,img) ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) for y_offset in range(8): ugfx.Label(0, 42 * y_offset, ugfx.width(), 20, text, parent=None, style=None, justification=ugfx.Label.CENTER) utime.sleep_ms(100) utime.sleep_ms(1000) loading_screen()
def download_nametag(self): payload = { "name": self.name, "org": self.org, "ext": self.filename.split('.')[-1] # file extension } headers = {'Content-Type': 'application/json'} data = (json.dumps(payload)).encode() r = urequests.post(self.url, data=data, headers=headers) if r.status_code == 200: ugfx.display_image(0, 0, bytearray(r.content)) if not self.IS_TEST: # Write it as a file f = open(self.filename, 'wb') f.write(bytearray(r.content)) f.close() else: print(r.text) raise Exception(r.text) r.close()
def show_weight(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) while True: input = dialogs.prompt_text("Please enter your weight.", false_text="Cancel") if is_int(input): break sleep.wfi() ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) while True: input = dialogs.prompt_text("Please enter your correct weight.", false_text="Cancel") if is_int(input): break sleep.wfi() ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") with dialogs.WaitingMessage("Please wait.", title="Processing..."): sleep.sleep_ms(2000) show_next_step()
def show_trains(self): ugfx.clear() ugfx.area(0, 0, 240, 25, ugfx.RED if self.has_error else ugfx.GRAY) title = get_title(self.station_data['locationName'], self.has_error) ugfx.text(5, 5, title, ugfx.WHITE if self.has_error else ugfx.BLACK) ugfx.text(195, 5, time_as_string(), ugfx.BLUE) names = self._get_names_container() names.show() row_num = 0 for service in self.station_data['trainServices']: departure = get_departure(service) if departure: names.text(5, 15 * row_num, service['destination'][0]['locationName'], ugfx.BLACK) ugfx.text(195, 25 + (15 * row_num), departure, ugfx.RED if is_red(service) else ugfx.BLUE) row_num += 1 ugfx.display_image(0, 300, 'trains/bottom.gif') self.should_redraw = False
def screen_1(): ugfx.display_image(0, 0, "splash1.bmp")
def display2(): ugfx.display_image(0,0,'apps/apps/rootzoll~dogerocketride/2.gif')
def screen_2(): ugfx.display_image(0, 0, "apps/sponsors/sponsors.gif")
def screen_1(): ugfx.display_image(0, 0, "/flash/apps/skippy~rabbit/bunny.bmp")
import time import network import wifi loc = utils = __import__("apps/lilafischneider~tilda-nmap/locations") bs = utils = __import__("apps/lilafischneider~tilda-nmap/bssids") MAXDIAMETER = 10 ugfx.init() buttons.init() buttons.disable_menu_reset() showMap = True ugfx.display_image(0,0,'apps/lilafischneider~tilda-nmap/map.gif') while showMap: try: apList = wifi.nic().list_aps() except OSError: # was not able to get ap list, # we will just try again continue # clear image before adding new data ugfx.display_image(0,0,'apps/lilafischneider~tilda-nmap/map.gif') for i in apList: # get the human readable version of the bssid bssid = '' for idx in range(5): bssid += str(hex(i['bssid'][idx])[2:4])
def kim(foo): ugfx.display_image(0, 0, "apps/home/kim.gif")
imu=IMU() neo = pyb.Neopix(pyb.Pin("PB13")) neo.display(0x04040404) ledg = pyb.LED(2) ival = imu.get_acceleration() if ival['y'] < 0: ugfx.orientation(0) else: ugfx.orientation(180) buttons.init() if not onboard.is_splash_hidden(): splashes = ["splash1.bmp"] for s in splashes: ugfx.display_image(0,0,s) delay = 2000 while delay: delay -= 1 if buttons.is_triggered("BTN_MENU"): break; if buttons.is_triggered("BTN_A"): break; if buttons.is_triggered("BTN_B"): break; if buttons.is_triggered("JOY_CENTER"): break; pyb.delay(1) onboard.hide_splash_on_next_boot(False)
### Author: Roderick Hodgson ### Description: Jeff Goldblum is staring at you ### Category: Creative ### License: MIT import ugfx, pyb, buttons from imu import IMU ugfx.init() imu=IMU() ugfx.clear() buttons.init() ugfx.set_default_font(ugfx.FONT_NAME) ugfx.display_image(0, 0, "apps/roderickhodgson~goldblum/goldblum.gif") EYES = ((119, 85), (207, 86)) WHITES = 20 PUPIL = 5 GRAVITY = -1 #1 = googley eyes, -1 = staring into your soul MAX_ACC = 10 def clamp(val, minmax): if val < -minmax: val = -minmax if val > minmax: val = minmax return val while True: pyb.wfi() ival = imu.get_acceleration()