more efficient
This commit is contained in:
parent
94f1ab5e21
commit
0d5b013fbc
BIN
ctdo.png
BIN
ctdo.png
Binary file not shown.
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
@ -2,6 +2,8 @@ import socket
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from random import shuffle
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
TCP_IP = '94.45.232.48'
|
TCP_IP = '94.45.232.48'
|
||||||
TCP_PORT = 1234
|
TCP_PORT = 1234
|
||||||
|
@ -21,26 +23,58 @@ c = '000000'
|
||||||
im = Image.open("ctdo.png")
|
im = Image.open("ctdo.png")
|
||||||
rgb_im = im.convert('RGB')
|
rgb_im = im.convert('RGB')
|
||||||
|
|
||||||
|
commandsarray=[]
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for a in range(100000):
|
starttime=time.time()
|
||||||
#xv=random.randint(0,flutwidth)
|
#xv=random.randint(0,flutwidth)
|
||||||
#yv=random.randint(0,flutheight)
|
#yv=random.randint(0,flutheight)
|
||||||
xv=flutwidth-width/2
|
xv=300
|
||||||
yv=height/2
|
yv=flutheight-height-100
|
||||||
for i in range(width):
|
_current_command=""
|
||||||
pixel_x=i-width/2+xv
|
|
||||||
for j in range(height):
|
pixelcoords=[]
|
||||||
pixel_y=j-height/2+yv
|
for _x in range(width):
|
||||||
#v1=hex(random.randint(0,255))[2:]
|
for _y in range(height):
|
||||||
#c=v1+v1+v1
|
pixelcoords+=[(_x,_y)]
|
||||||
|
|
||||||
|
shuffle(pixelcoords)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for i,j in pixelcoords:
|
||||||
r, g, b = rgb_im.getpixel((i, j))
|
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")
|
||||||
|
|
||||||
|
|
||||||
#c=hex(r)+hex(g)+hex(b)
|
while True:
|
||||||
#c=hex(r)
|
try:
|
||||||
#s.send("PX {0} {1} {2}\n".format(pixel_x, pixel_y, c))
|
starttime=time.time()
|
||||||
s.send( ('PX %d %d %02x%02x%02x\n' % (pixel_x,pixel_y,r,g,b)).encode())
|
for command in commandsarray:
|
||||||
print(".")
|
|
||||||
|
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()
|
exit()
|
||||||
|
|
Loading…
Reference in New Issue