pixelserver2/apps/example2.py

69 lines
1.5 KiB
Python
Raw Normal View History

2024-10-28 17:10:03 +00:00
#!/usr/bin/env python3
import os
import sys
import random
import time
# Groesse des Bildschirms bestimmen
Nx = int(sys.argv[1])
Ny = int(sys.argv[2])
# Bestimme den Parameter
time_ms = 100
try:
time_ms = int(sys.argv[3])
except:
pass
# Puffer fuer Pixel erstellen und mit 0 initialisieren
buffer = bytearray(b"\x00" * (4 * Nx * Ny))
curPixel = 0
while True:
# Zufaellige Pixel waeheln
# rot
x_r = random.randint(0, Nx-1)
y_r = random.randint(0, Ny-1)
i_r = 4*(x_r+Nx*y_r)
# gruen
x_g = random.randint(0, Nx-1)
y_g = random.randint(0, Ny-1)
i_g = 4*(x_g+Nx*y_g)
# blau
x_b = random.randint(0, Nx-1)
y_b = random.randint(0, Ny-1)
i_b = 4*(x_b+Nx*y_b)
# weiss
x_w = random.randint(0, Nx-1)
y_w = random.randint(0, Ny-1)
i_w = 4*(x_w+Nx*y_w)
# Pixel in Puffer schreiben
# rot
buffer[i_r+0] = 0xff # Rotanteil
buffer[i_r+1] = 0x00 # Gruenanteil
buffer[i_r+2] = 0x00 # Blauanteil
buffer[i_r+3] = 0x00
# gruen
buffer[i_g+0] = 0x00 # Rotanteil
buffer[i_g+1] = 0xff # Gruenanteil
buffer[i_g+2] = 0x00 # Blauanteil
buffer[i_g+3] = 0x00
# blau
buffer[i_b+0] = 0x00 # Rotanteil
buffer[i_b+1] = 0x00 # Gruenanteil
buffer[i_b+2] = 0xff # Blauanteil
buffer[i_b+3] = 0x00
# weiss
buffer[i_w+0] = 0x00 # Rotanteil
buffer[i_w+1] = 0x00 # Gruenanteil
buffer[i_w+2] = 0x00 # Blauanteil
buffer[i_w+3] = 0xff
# Zeige den Puffer an
os.write(1, buffer)
# warte time_ms ms
time.sleep(time_ms*0.001)