From ea4d36c87258c345eee3207b95da4d5d65310907 Mon Sep 17 00:00:00 2001 From: T Date: Sun, 10 Nov 2024 02:28:55 +0100 Subject: [PATCH] Spot Animation --- apps/spot.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config.py | 1 + 2 files changed, 70 insertions(+) create mode 100755 apps/spot.py diff --git a/apps/spot.py b/apps/spot.py new file mode 100755 index 0000000..cba77e9 --- /dev/null +++ b/apps/spot.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import os +import sys +import random + +import pygame + + +class SpotDisplay: + FRAMES = 5 + + PATH = [ + *((8 * 1, 8 * i) for i in range(1, 4)), + *((8 * i, 8 * 3) for i in range(2, 9)), + *((8 * 8, 8 * i) for i in range(2, 0, -1)), + *((8 * i, 8 * 1) for i in range(7, 1, -1)), + ] + + def __init__(self, width: int, height: int, debug: bool = False): + self.width = width + self.height = height + self.debug = debug + + pygame.init() + if not self.debug: + self.screen = pygame.Surface((self.width, self.height), flags=pygame.SRCALPHA, depth=32) + else: + self.screen = pygame.display.set_mode((self.width, self.height)) + + self.clock = pygame.time.Clock() + self.i = 0 + self.stop = None + self.sleep = 0 + + def display(self): + while True: + self.clock.tick(self.FRAMES) + + if self.sleep: + self.sleep -= 1 + continue + + self.screen.fill((0, 0, 0, 120)) + pygame.draw.rect(self.screen, (0, 0, 0, 255), pygame.Rect(*self.PATH[self.i], 8, 8)) + self.i = (self.i + 1) % len(self.PATH) + + if self.stop == 0 or self.stop is None: + if self.stop is not None: + self.sleep = 7 * self.FRAMES + self.stop = random.randint(8 * self.FRAMES, 20 * self.FRAMES) + self.stop -= 1 + + if not self.debug: + os.write(1, pygame.image.tostring(self.screen, "RGBA")) + else: + pygame.display.flip() + + +if __name__ == "__main__": + try: + Nx = int(sys.argv[1]) # Breite des Displays + Ny = int(sys.argv[2]) # Höhe des Displays + debug = False + except IndexError: + Nx, Ny = 80, 40 + debug = True + + SpotDisplay(Nx, Ny, debug).display() diff --git a/config.py b/config.py index 60cb5c1..ab56f5b 100644 --- a/config.py +++ b/config.py @@ -46,6 +46,7 @@ Apps = [ AppConfig(guiname="Wolfram", name="wolfram", cmd="./wolfram.py"), AppConfig(guiname="Digi Clock", name="digiclock", cmd="./digi_clock.py"), AppConfig(guiname="Text Scroller MQTT", name="textscroll", cmd="./textscroll.py"), + AppConfig(guiname="Spot", name="spot", cmd="./spot.py", white=True), AppConfig(guiname="Flicker", name="flicker", cmd="./flicker"), AppConfig(guiname="Pixelflut", name="pixelflut", cmd="./pixelflut", persistent=True),