From 2621b90ed2347ce0d1655db67c201aeec7674afe Mon Sep 17 00:00:00 2001 From: m Date: Tue, 1 Jan 2019 15:54:05 +0100 Subject: [PATCH] Initial commit --- README.md | 3 +++ fading_pixel.py | 42 ++++++++++++++++++++++++++++++++++++++++++ sine.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 README.md create mode 100755 fading_pixel.py create mode 100755 sine.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..d655d39 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Pixelthud + +Animationen für die Decken-LED-Matrix im Chaospott. Kompatibel zu Pixelserver2 diff --git a/fading_pixel.py b/fading_pixel.py new file mode 100755 index 0000000..0c3421a --- /dev/null +++ b/fading_pixel.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import sys +import os +import numpy as np +import pygame + +Nx = int(sys.argv[1]) +Ny = int(sys.argv[2]) +try: + fps = float(sys.argv[3]) +except (IndexError, ValueError): + fps = 1.0 + + +def point2idx(x,y): + return 3*(x+Nx*y) + +def set_pixel_max(buffer, x, y): + idx = point2idx(x,y) + for i in range(3): + buffer[idx+i] = max(0x00, buffer[idx+i]-1) + +def set_pixel_rand(buffer, x, y): + idx = point2idx(x,y) + for i in range(3): + buffer[idx+i] = np.random.randint(0x00, 0xff) + +clock = pygame.time.Clock() +buffer = bytearray(b"\x00"*(3*Nx*Ny)) + +i = 0 +while True: + i = i + 1 + for px in range(Nx): + for py in range(Ny): + set_pixel_max(buffer, px, py) + for j in range(10): + set_pixel_rand(buffer, np.random.randint(0, Nx), np.random.randint(0, Ny)) + if i > 100: + os.write(1, buffer) + clock.tick_busy_loop(fps) \ No newline at end of file diff --git a/sine.py b/sine.py new file mode 100755 index 0000000..f3bf5a4 --- /dev/null +++ b/sine.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import sys +import os +import numpy as np +import pygame + +Nx = int(sys.argv[1]) +Ny = int(sys.argv[2]) +try: + frequency = float(sys.argv[3]) +except (IndexError, ValueError): + frequency = 5 + +fps = 30 +amplitude = 105 +offset = 150 +t = 0 + +x,y = np.meshgrid(np.linspace(0, 2*np.pi * min(1, Nx/Ny), Nx), np.linspace(0, 2*np.pi * min(1, Ny/Nx), Ny)) +kx = x + y + +clock = pygame.time.Clock() + +while True: + t = t + 1e-3 + R = amplitude * np.sin(kx - 2 * np.pi * frequency * t) + offset + G = amplitude * np.sin(kx - 2 * np.pi * frequency * t + 2*np.pi/3) + offset + B = amplitude * np.sin(kx - 2 * np.pi * frequency * t + 4*np.pi/3) + offset + + out = np.dstack((R,G,B)).astype(np.uint8).tobytes() + os.write(1, out) + clock.tick_busy_loop(fps) \ No newline at end of file