def set_animation(self, sel): if self.available is None: try: self.available = self.get_all_animations() except Exception as e: self.available = [] if self.interactive: raise e else: print(e) if not self.available: dcfurs.set_frame(UNUSABLE_FACE) return None try: self.selected = sel % len(self.available) while self.selected < 0: self.selected = len(self.available) + self.selected self.anim = self.available[self.selected]() print(self.anim.__class__.__name__) return except Exception as e: dcfurs.set_frame(EXCEPTION_FACE) if self.interactive: raise e else: print(e) return None
def random(): x = choice(prebuilt) if type(x) is str: render(x) elif callable(x): x() else: dcfurs.set_frame(x)
def random(color=0xffffff): x = choice(prebuilt) if type(x) is str: render(x, color) elif callable(x): x(color) else: dcfurs.set_frame(x, color)
def main(self): ## Program the serial number into the BLE module, which ought ## to have finished booting by now. if badge.ble: badge.ble_set("serial", "0x%04x" % dcfurs.serial()) badge.ble_set("cooldown", "%d" % settings.blecooldown) ## Select the user's preferred boot animation. self.set_animation(0) if settings.bootanim: try: self.set_animation( self.available.index(getattr(animations, settings.bootanim)) ) except Exception as e: if self.interactive: raise e else: print(e) while True: if self.ival <= 0 and self.anim: try: self.anim.draw() self.ival = self.anim.interval except Exception as e: dcfurs.set_frame(EXCEPTION_FACE) self.ival = 1000 if self.interactive: raise e else: print(e) self.handle_events() ## Run the animation timing if self.ival > 50: pyb.delay(50) self.ival -= 50 else: pyb.delay(self.ival) self.ival = 0 ## Attempt to suspend the badge between animations badge.trysuspend()
def draw(self): self.face() dcfurs.set_frame(self.fbuf)
def draw(self): self.updatePosition() dcfurs.set_frame(self.fbuf)
raise e else: print(e) self.handle_events() ## Run the animation timing if self.ival > 50: pyb.delay(50) self.ival -= 50 else: pyb.delay(self.ival) self.ival = 0 ## Attempt to suspend the badge between animations badge.trysuspend() main = Main() if __name__ == "__main__": try: main.main() except Exception as e: if not main.interactive: dcfurs.set_frame(UNUSABLE_FACE) raise e except KeyboardInterrupt as e: # Shiny python shell face dcfurs.set_frame(PYTHON_SHELL_FACE) # Make life easier. main.interactive = True raise e