Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
RvdBongard | 70216494f9 | |
blast0r | 2060476480 | |
blast0r | a9bb18e7c3 | |
interfisch | 1a8da07e0e | |
interfisch | 15d54cdce3 | |
interfisch | a86320aa18 | |
interfisch | e837e4b94f | |
interfisch | 20ef7b4b2b | |
RvdBongard | 9878269952 | |
RvdBongard | bd52a6ccb9 | |
RvdBongard | 2d66fe8a2f | |
interfisch | 812394b611 | |
interfisch | 1469a2fb16 |
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
BIN
ctdo.png
BIN
ctdo.png
Binary file not shown.
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.2 KiB |
101
eh18-image.py
101
eh18-image.py
|
@ -4,6 +4,7 @@ import time
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import sys
|
||||||
|
|
||||||
TCP_IP = '94.45.232.48'
|
TCP_IP = '94.45.232.48'
|
||||||
TCP_PORT = 1234
|
TCP_PORT = 1234
|
||||||
|
@ -12,69 +13,87 @@ BUFFER_SIZE = 4096
|
||||||
flutwidth = 1920
|
flutwidth = 1920
|
||||||
flutheight = 1080
|
flutheight = 1080
|
||||||
|
|
||||||
width=200
|
|
||||||
height=200
|
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((TCP_IP, TCP_PORT))
|
s.connect((TCP_IP, TCP_PORT))
|
||||||
|
|
||||||
c = '000000'
|
image=sys.argv[1] #image name
|
||||||
|
#Load the Image
|
||||||
|
im = Image.open(image)
|
||||||
|
rgb_im = im.convert('RGBA')
|
||||||
|
width, height = im.size #get image size
|
||||||
|
|
||||||
im = Image.open("ctdo.png")
|
def randomnumber(pseed,pmin,pmax,v1,v2,v3):
|
||||||
rgb_im = im.convert('RGB')
|
return (pseed*v1+pseed^2*v2+pseed^3*v3)%(pmax-pmin)+pmin
|
||||||
|
|
||||||
commandsarray=[]
|
|
||||||
|
newseed=(int)(time.time()/60) #seed based on timestamp (full minutes)
|
||||||
|
seed=newseed
|
||||||
|
|
||||||
|
user=int(sys.argv[2]) #1..n
|
||||||
|
parts=int(sys.argv[3]) #n users
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
starttime=time.time()
|
|
||||||
#xv=random.randint(0,flutwidth)
|
|
||||||
#yv=random.randint(0,flutheight)
|
|
||||||
xv=300
|
|
||||||
yv=flutheight-height-100
|
|
||||||
_current_command=""
|
|
||||||
|
|
||||||
pixelcoords=[]
|
pixelcoords=[]
|
||||||
for _x in range(width):
|
for _x in range(width):
|
||||||
for _y in range(height):
|
for _y in range(height):
|
||||||
pixelcoords+=[(_x,_y)]
|
pixelcoords+=[(_x,_y)]
|
||||||
|
|
||||||
shuffle(pixelcoords)
|
random.seed(42)
|
||||||
|
random.shuffle(pixelcoords) #pseudorandom order
|
||||||
|
print(pixelcoords)
|
||||||
|
|
||||||
|
pixelcoords=pixelcoords[int(len(pixelcoords)/parts)*(user-1):int(len(pixelcoords)/parts)*(user)] #divide in parts for multiple connection
|
||||||
|
|
||||||
|
while True: #Mainloop
|
||||||
|
starttime=time.time()
|
||||||
|
commandsarray=[]
|
||||||
|
seed=newseed
|
||||||
|
print("Seed: "+str(seed))
|
||||||
|
|
||||||
|
xv=randomnumber(seed,width/2,flutwidth-width/2, 42,-24,4) #x position of image
|
||||||
|
yv=randomnumber(seed,height/2,flutheight-height/2, 43,-23,3) #y ""
|
||||||
|
print("xv="+str(xv)+ "yv="+str(yv))
|
||||||
|
_current_command=""
|
||||||
|
|
||||||
|
for i,j in pixelcoords: #i,j as xy coordinates from image
|
||||||
|
r, g, b,a = rgb_im.getpixel((i, j))
|
||||||
|
#Do stupid stuffz with p1x3ls
|
||||||
|
|
||||||
|
if a<=127:
|
||||||
|
continue
|
||||||
|
#if r>127:
|
||||||
|
# continue #skip bright pixels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_current_command+='PX %d %d %02x%02x%02x\n' % (i+xv-width/2,j+yv-height/2,r,g,b) #rgb
|
||||||
|
#_current_command+='PX %d %d %02x\n' % (i+xv-width/2,j+yv-height/2,r) #monochrome only red channel
|
||||||
|
|
||||||
for i,j in pixelcoords:
|
if len(_current_command)>=1400: #divide in packets smaller than 1500 byte
|
||||||
r, g, b = rgb_im.getpixel((i, j))
|
commandsarray+=[_current_command.encode()] #append packet
|
||||||
#if r>127:
|
_current_command=""
|
||||||
# continue #skip bright pixels
|
|
||||||
#r=255-r
|
|
||||||
|
|
||||||
#_current_command+='PX %d %d %02x%02x%02x\n' % (i+xv,j+yv,r,g,b) #rgb
|
commandsarray+=[_current_command.encode()] #append last packet
|
||||||
_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")
|
||||||
|
|
||||||
print("Generated Commands in "+str(time.time()-starttime)+" seconds")
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while seed==newseed: #as long as position did not change
|
||||||
try:
|
try:
|
||||||
starttime=time.time()
|
starttime=time.time()
|
||||||
for command in commandsarray:
|
for command in commandsarray:
|
||||||
|
s.send(command)
|
||||||
|
|
||||||
s.send(command)
|
print("Send Image in "+str(time.time()-starttime)+" seconds")
|
||||||
|
except BrokenPipeError: #Brokn Pipe? Reconnect!!
|
||||||
|
print("BrokenPipeError. Reconnecting")
|
||||||
print("Send Image in "+str(time.time()-starttime)+" seconds")
|
s.close()
|
||||||
except BrokenPipeError:
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
print("BrokenPipeError. Reconnecting")
|
s.connect((TCP_IP, TCP_PORT)) #reconnect
|
||||||
s.close()
|
print("reconnected")
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.connect((TCP_IP, TCP_PORT)) #reconnect
|
|
||||||
print("reconnected")
|
|
||||||
|
|
||||||
|
newseed=(int)(time.time()/60)
|
||||||
|
|
||||||
exit()
|
exit()
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue