def show(self): packed = np.packbits(np.pad((self.rawbuf[::-1, :, 0] & 0x80) > 0, ((3, 0), (0, 0)), mode='constant'), axis=0) scrollphat.set_buffer(packed[0].tolist()) scrollphat.update() super().show()
def scroll_life(delay): def count_neighbours(ibuf, i, j): tot=0 for x,y in ((-1,-1), (-1,0), (-1,1), ( 0,-1) , (0,1), (+1,-1), (+1,0), (+1,1)): ix=(i+x)%11 jy=(j+y)%5 tot+=ibuf[ix][jy] return tot def buffer(ibuf): return [ibuf2buf[tuple(v)] for v in ibuf] def rand_ibuf(): return [[(random.random()>0.8)+0 for j in range(5)] for i in range(11)] def glider_ibuf(): return [[0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,1,0,0], [0,1,0,0,0], [0,1,1,1,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0]] ibuf=rand_ibuf() ibuf2buf={(i,j,k,l,m): (i<<0)+(j<<1)+(k<<2)+(l<<3)+(m<<4) for i in (0,1) for j in (0,1) for k in (0,1) for l in (0,1) for m in (0,1)} samecount=0 while True: ibufbuf=copy.deepcopy(ibuf) for i in range(11): for j in range(5): c=count_neighbours(ibufbuf, i, j) if ibuf[i][j]: if c in (0,1,4,5,6,7): ibuf[i][j]=0 else: if c in (3,): ibuf[i][j]=1 buf=buffer(ibuf) scrollphat.set_buffer(buf) scrollphat.update() time.sleep(delay) if ibufbuf==ibuf: samecount+=1 if samecount>20: ibuf=rand_ibuf()
def bufferFall(self, buf): '''Sets the buffer for snow''' if self.verbose: print('Running Snow.bufferFall, buf: %s' % buf) scrollphat.set_buffer(buf) scrollphat.update() time.sleep(self.fallSpeed)
def sine(): timer = 0 i = 0 buf = [0] * 11 while (timer < 2): try: for x in range(0, 11): y = (math.sin( (i + (x * 10)) / 10.0) + 1) # Produces range from 0 to 2 y *= 2.5 # Scale to 0 to 5 buf[x] = 1 << int(y) scrollphat.set_buffer(buf) scrollphat.update() time.sleep(0.005) timer += 0.005 i += 1 except KeyboardInterrupt: scrollphat.clear() sys.exit(-1)
#!/usr/bin/env python import scrollphat import math import time import sys i = 0 buf = [0] * 11 scrollphat.set_brightness(20) while True: try: for x in range(0, 11): y = math.sin((i + (x * 10)) / 10.0) + 1 # Produces range from 0 to 2 y *= 2.5 # Scale to 0 to 5 buf[x] = 1 << int(y) scrollphat.set_buffer(buf) scrollphat.update() time.sleep(0.005) i += 1 except KeyboardInterrupt: scrollphat.clear() sys.exit(-1)
#!/usr/bin/env python import scrollphat import math import time import sys i = 0 buf = [0] * 11 scrollphat.set_brightness(20) while True: try: for x in range(0, 11): y = (math.sin( (i + (x * 10)) / 10.0) + 1) # Produces range from 0 to 2 y *= 2.5 # Scale to 0 to 5 buf[x] = 1 << int(y) scrollphat.set_buffer(buf) scrollphat.update() time.sleep(0.005) i += 1 except KeyboardInterrupt: scrollphat.clear() sys.exit(-1)