diff --git a/ctdo.png b/ctdo.png index 3a98812..72b3cc8 100644 Binary files a/ctdo.png and b/ctdo.png differ diff --git a/eh18-image.py b/eh18-image.py index 76e7753..0b35a27 100644 --- a/eh18-image.py +++ b/eh18-image.py @@ -2,6 +2,8 @@ import socket import random import time from PIL import Image +from random import shuffle +import numpy as np TCP_IP = '94.45.232.48' TCP_PORT = 1234 @@ -21,26 +23,58 @@ c = '000000' im = Image.open("ctdo.png") rgb_im = im.convert('RGB') +commandsarray=[] if __name__ == '__main__': - for a in range(100000): - #xv=random.randint(0,flutwidth) - #yv=random.randint(0,flutheight) - xv=flutwidth-width/2 - yv=height/2 - for i in range(width): - pixel_x=i-width/2+xv - for j in range(height): - pixel_y=j-height/2+yv - #v1=hex(random.randint(0,255))[2:] - #c=v1+v1+v1 - r, g, b = rgb_im.getpixel((i, j)) + starttime=time.time() + #xv=random.randint(0,flutwidth) + #yv=random.randint(0,flutheight) + xv=300 + yv=flutheight-height-100 + _current_command="" + + pixelcoords=[] + for _x in range(width): + for _y in range(height): + pixelcoords+=[(_x,_y)] + + shuffle(pixelcoords) - #c=hex(r)+hex(g)+hex(b) - #c=hex(r) - #s.send("PX {0} {1} {2}\n".format(pixel_x, pixel_y, c)) - s.send( ('PX %d %d %02x%02x%02x\n' % (pixel_x,pixel_y,r,g,b)).encode()) - print(".") + + + for i,j in pixelcoords: + r, g, b = rgb_im.getpixel((i, j)) + #if r>127: + # continue #skip bright pixels + #r=255-r + + #_current_command+='PX %d %d %02x%02x%02x\n' % (i+xv,j+yv,r,g,b) #rgb + _current_command+='PX %d %d %02x\n' % (i+xv,j+yv,r) #monochrome only red channel + if len(_current_command)>=1400: + commandsarray+=[_current_command.encode()] #append packet + _current_command="" + + commandsarray+=[_current_command.encode()] #append last packet + + print("Generated Commands in "+str(time.time()-starttime)+" seconds") + + + while True: + try: + starttime=time.time() + for command in commandsarray: + + s.send(command) + + + print("Send Image in "+str(time.time()-starttime)+" seconds") + except BrokenPipeError: + print("BrokenPipeError. Reconnecting") + s.close() + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((TCP_IP, TCP_PORT)) #reconnect + print("reconnected") + exit()