commit d3202f30d1d2b6049c823f96912f2c6be09e98f7
Author: clerie <git@clerie.de>
Date:   Sun Oct 10 12:14:14 2021 +0200

    Pixelflut session 2021-10-09 FeM Office

diff --git a/gif.py b/gif.py
new file mode 100755
index 0000000..695bc10
--- /dev/null
+++ b/gif.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+
+import socket
+import random
+import time
+import pprint
+
+IP_ADDRESS = "2001:638:904:ffc9::2"
+PORT = 1234
+
+O_X = 100
+O_Y = 500
+
+from PIL import Image
+
+gif = Image.open("tube.gif")
+print(gif.n_frames)
+
+frames = []
+try:
+    for i in range(gif.n_frames):
+        gif.seek(i)
+
+        try:
+            d = gif.duration
+        except AttributeError:
+            d = 0.1
+
+        im = gif.copy()
+
+        im = im.convert("RGB")
+        im.thumbnail((200,300), Image.ANTIALIAS)
+
+        _,_,w,h = im.getbbox()
+
+
+        stream = []
+        for x in range(w):
+            for y in range(h):
+                r,g,b = im.getpixel((x,y))
+                stream.append("PX {} {} {:02X}{:02X}{:02X}\n".format(x+O_X,y+O_Y,r,g,b).encode("utf-8"))
+
+        random.shuffle(stream)
+        #pprint.pprint(stream)
+
+        frames.append({
+            "time": d,
+            "stream": stream,
+        })
+except EOFError:
+    pass
+
+
+s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+s.connect((IP_ADDRESS, PORT))
+
+frames_n = len(frames)
+f = 0
+while True:
+    stream = frames[f]["stream"]
+    end_time = time.time() + frames[f]["time"]
+
+    stream_n = len(stream)
+    print("stream_n:", stream_n)
+    p = 0
+    while time.time() < end_time:
+        for x in range(1000):
+            s.send(stream[p])
+            p += 1
+            if p >= stream_n:
+                p = 0
+
+    f +=1
+    if f >= frames_n:
+        f = 0
diff --git a/grid.py b/grid.py
new file mode 100644
index 0000000..3675f6c
--- /dev/null
+++ b/grid.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import socket
+import random
+
+IP_ADDRESS = "2001:638:904:ffc9::2"
+PORT = 1234
+
+W = 1920
+H = 1080
+
+s_w = 10
+s_c = "FFC0CB"
+
+s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+s.connect((IP_ADDRESS, PORT))
+
+x = W//2
+y = H//2
+d = 0
+c = 0
+
+while True:
+    if x > W or x < 0 or y > H or y < 0:
+        x = W//2
+        y = H//2
+
+    if c >= 0:
+        d = (d+random.randint(-1,1)) % 4
+        c = random.randint(0, 10)
+
+    if d == 0:
+        x += 0
+        y += -1
+    elif d == 1:
+        x += 1
+        y += 0
+    elif d == 2:
+        x += 0
+        y += 1
+    elif d == 3:
+        x += -1
+        y += 0
+
+    s.send("PX {} {} {}\n".format(x,y, s_c).encode("utf-8"))
+
+    c += 1
diff --git a/snake.py b/snake.py
new file mode 100755
index 0000000..e514e01
--- /dev/null
+++ b/snake.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import socket
+import random
+
+IP_ADDRESS = "2001:638:904:ffc9::2"
+PORT = 1234
+
+W = 1920
+H = 1080
+
+s_w = 10
+s_c = "FFC0CB"
+
+s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+s.connect((IP_ADDRESS, PORT))
+
+x = W//2
+y = H//2
+d = 0
+c = 0
+
+while True:
+
+    if c < 0:
+        d = (d+random.randint(-1,1)) % 4
+        c = random.randint(80, 100)
+
+    if d == 0:
+        x += 0
+        y += -1
+    elif d == 1:
+        x += 1
+        y += 0
+    elif d == 2:
+        x += 0
+        y += 1
+    elif d == 3:
+        x += -1
+        y += 0
+
+    x = x%W
+    y = y%H
+
+    for i in range(s_w):
+        j = i - s_w//2
+        s.send("PX {} {} {}\n".format(x+j,y+j, s_c).encode("utf-8"))
+
+    c -= 1