Compare commits

...

13 Commits

6 changed files with 67 additions and 41 deletions

BIN
chaoswest-logo-small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
chaoswest-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

BIN
ctdo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -4,6 +4,7 @@ import time
from PIL import Image
from random import shuffle
import numpy as np
import sys
TCP_IP = '94.45.232.48'
TCP_PORT = 1234
@ -12,69 +13,87 @@ BUFFER_SIZE = 4096
flutwidth = 1920
flutheight = 1080
width=200
height=200
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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")
rgb_im = im.convert('RGB')
def randomnumber(pseed,pmin,pmax,v1,v2,v3):
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__':
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)
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:
r, g, b = rgb_im.getpixel((i, j))
#if r>127:
# continue #skip bright pixels
#r=255-r
if len(_current_command)>=1400: #divide in packets smaller than 1500 byte
commandsarray+=[_current_command.encode()] #append packet
_current_command=""
#_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
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:
try:
starttime=time.time()
for command in commandsarray:
while seed==newseed: #as long as position did not change
try:
starttime=time.time()
for command in commandsarray:
s.send(command)
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")
print("Send Image in "+str(time.time()-starttime)+" seconds")
except BrokenPipeError: #Brokn Pipe? Reconnect!!
print("BrokenPipeError. Reconnecting")
s.close()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT)) #reconnect
print("reconnected")
newseed=(int)(time.time()/60)
exit()

BIN
origamisHase.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

7
start.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
maxCount=10
fileName=ctdo.png
for i in $( seq 1 $maxCount); do
echo starting $i of $maxCount
python3 eh18-image.py $fileName $i $maxCount &
done