You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

#!/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