connect to pixelflut via direct socket

main
Felix Pankratz 3 years ago
parent 185adf8df1
commit 1d53c4a731

@ -0,0 +1,44 @@
#!/usr/bin/env python3
import sys
import io
import socket
sys.path.append('..')
from waves import create_wpotd
SERVER_IP = '192.168.178.75'
SERVER_PORT = 1234
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
#buf = io.BytesIO()
#surface = create_wpotd(buf)
#
#data = surface.get_data()
#pixels = data.hex()
#
#x, y = 0, 0
#for hexpx in chunker(pixels, 8):
# if x > 1919:
# x = 0
# y += 1
# pxstr = f'PX {x} {y} {hexpx[:6]}'
# x += 1
# print(pxstr)
def surface_to_pixelflut(surface):
data = surface.get_data()
pixels = data.hex()
x, y = 0, 0
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((SERVER_IP, SERVER_PORT))
for hexpx in chunker(pixels, 8):
if x > 1919:
x = 0
y += 1
pxstr = f'PX {x} {y} {hexpx[:6]}\n'
x += 1
if hexpx[6:8] == '00':
continue
s.sendall(pxstr.encode())
Loading…
Cancel
Save