position is time seeded
This commit is contained in:
parent
0d5b013fbc
commit
1469a2fb16
BIN
ctdo.png
BIN
ctdo.png
Binary file not shown.
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
113
eh18-image.py
113
eh18-image.py
|
@ -21,60 +21,81 @@ s.connect((TCP_IP, TCP_PORT))
|
|||
c = '000000'
|
||||
|
||||
im = Image.open("ctdo.png")
|
||||
rgb_im = im.convert('RGB')
|
||||
rgb_im = im.convert('RGBA')
|
||||
|
||||
commandsarray=[]
|
||||
|
||||
|
||||
|
||||
def randomnumber(pseed,pmin,pmax,v1,v2,v3):
|
||||
return (pseed*v1+pseed^2*v2+pseed^3*v3)%(pmax-pmin)+pmin
|
||||
|
||||
|
||||
newseed=(int)(time.time()/60)
|
||||
seed=newseed
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
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:
|
||||
starttime=time.time()
|
||||
commandsarray=[]
|
||||
seed=newseed
|
||||
print("Seed: "+str(seed))
|
||||
#xv=random.randint(0,flutwidth)
|
||||
#yv=random.randint(0,flutheight)
|
||||
|
||||
s.send(command)
|
||||
#xv=random.randint(width/2,flutwidth-width/2)
|
||||
#yv=random.randint(height/2,flutheight-height/2)
|
||||
xv=randomnumber(seed,width/2,flutwidth-width/2, 1234,-242,4)
|
||||
yv=randomnumber(seed,height/2,flutheight-height/2, 1423,-122,3)
|
||||
print("xv="+str(xv)+ "yv="+str(yv))
|
||||
_current_command=""
|
||||
|
||||
pixelcoords=[]
|
||||
for _x in range(width):
|
||||
for _y in range(height):
|
||||
pixelcoords+=[(_x,_y)]
|
||||
|
||||
shuffle(pixelcoords)
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
for i,j in pixelcoords:
|
||||
r, g, b,a = rgb_im.getpixel((i, j))
|
||||
if a!=255:
|
||||
continue
|
||||
#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-width/2,j+yv-height/2,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 seed==newseed:
|
||||
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")
|
||||
|
||||
newseed=(int)(time.time()/60)
|
||||
|
||||
|
||||
exit()
|
||||
|
|
Loading…
Reference in New Issue