From 2bc55ca5d69b8104f083982e619e97b94730e279 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Sun, 4 Dec 2022 04:50:28 +0100 Subject: [PATCH] Add a simple pygame demo This allows to see patterns on a desktop without testing on Omnia. However, this will display different color since the color profile for the actual LEDs is not known (to me). --- pygame_demo.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 pygame_demo.py diff --git a/pygame_demo.py b/pygame_demo.py new file mode 100755 index 0000000..a14437c --- /dev/null +++ b/pygame_demo.py @@ -0,0 +1,61 @@ +#!/bin/python3 + +from omnia import leds +import pygame + +# Re-implementation of LED in order to handle it ourself + +class MyLED(leds.LED): + def __init__(self, alias, order): + self.alias = alias + self._state = leds.LedState( + r = 0, + g = 0, + b = 0, + brightness = 0, + autonomous = False, + ) + self.order = order + self.pgled = PGLED(order) + @property + def state(self): + return self._state + def set(self, state): + self._state = state + self.pgled.show(state) + +class PGLED: + """This holds a pygame object to display the LED""" + SIZE = 30 # px incl. margins + BULB = 6 # px radius + def __init__(self, order): + self.order = order + self.rect = pygame.Rect(self.SIZE * self.order, 0, self.SIZE, self.SIZE) + self.surface = None + + def set_surface(self, surf): + self.surface = surf + + def show(self, state: leds.LedState): + # Fill with black + black = pygame.Color(0,0,0) + pygame.draw.rect(self.surface, black, self.rect) + # Draw the circle with required color + # And respect the brightness + color = pygame.Color(state.r * state.brightness//255, state.g * state.brightness//255, state.b * state.brightness//255) + pygame.draw.circle(self.surface, color, self.rect.center, self.BULB) + pygame.display.flip() + +my_strip = leds.LedStrip([MyLED(al, i) for i, al in enumerate(leds.omnia_led_order)]) + +w = PGLED.SIZE * len(my_strip) +h = PGLED.SIZE + +pygame.init() +pygame.mixer.quit() +display = pygame.display.set_mode((w, h)) +display.fill((0,0,0)) +pygame.display.flip() + +for led in my_strip: + led.pgled.set_surface(display)