position is time seeded

This commit is contained in:
interfisch 2018-03-31 15:20:35 +02:00
parent 0d5b013fbc
commit 1469a2fb16
2 changed files with 67 additions and 46 deletions

BIN
ctdo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -21,16 +21,33 @@ s.connect((TCP_IP, TCP_PORT))
c = '000000' c = '000000'
im = Image.open("ctdo.png") 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__': if __name__ == '__main__':
while True:
starttime=time.time() starttime=time.time()
commandsarray=[]
seed=newseed
print("Seed: "+str(seed))
#xv=random.randint(0,flutwidth) #xv=random.randint(0,flutwidth)
#yv=random.randint(0,flutheight) #yv=random.randint(0,flutheight)
xv=300
yv=flutheight-height-100 #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="" _current_command=""
pixelcoords=[] pixelcoords=[]
@ -44,13 +61,15 @@ if __name__ == '__main__':
for i,j in pixelcoords: for i,j in pixelcoords:
r, g, b = rgb_im.getpixel((i, j)) r, g, b,a = rgb_im.getpixel((i, j))
if a!=255:
continue
#if r>127: #if r>127:
# continue #skip bright pixels # continue #skip bright pixels
#r=255-r #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%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 _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: if len(_current_command)>=1400:
commandsarray+=[_current_command.encode()] #append packet commandsarray+=[_current_command.encode()] #append packet
_current_command="" _current_command=""
@ -60,7 +79,7 @@ if __name__ == '__main__':
print("Generated Commands in "+str(time.time()-starttime)+" seconds") print("Generated Commands in "+str(time.time()-starttime)+" seconds")
while True: while seed==newseed:
try: try:
starttime=time.time() starttime=time.time()
for command in commandsarray: for command in commandsarray:
@ -76,5 +95,7 @@ if __name__ == '__main__':
s.connect((TCP_IP, TCP_PORT)) #reconnect s.connect((TCP_IP, TCP_PORT)) #reconnect
print("reconnected") print("reconnected")
newseed=(int)(time.time()/60)
exit() exit()