def set_colors(self,path, tags, args, source): # which user will be determined by path: # we just throw away all slashes and join together what's left #print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source)) pixels = [] for i in range(0,len(args)/3): pixel = (args[i*3],args[i*3+1],args[i*3+2]) pixels.append( pixel ) #print "Pixels: %s"%str(pixels) #print "Time: "+str((time.time()*1000) % 10000) octoapi.write(pixels) self.lastwrite=time.time() self.server.lastpixels = pixels
pass def render(self, pixels): for i in range(len(pixels)): alive = 0 if i == 0 and pixels[i + 1] == on: alive += 1 elif i > 0 and i < len(pixels) - 1: if pixels[i - 1] == on: alive += 1 if pixels[i + 1] == on: alive += 1 elif i == len(pixels) - 1 and pixels[i - 1] == on: alive += 1 if alive == 1: pixels[i] = on else: pixels[i] = off print pixels return pixels if __name__ == "__main__": import octoapi off = (0,0,0) on = (0,1023,0) pixels = [(),(),(),(),(),(),(),()] for i in range(len(pixels)): pixels[i] = random.choice([on, off]) c = GameOfLife() import time while True: c.update(0.04) c.render(pixels) octoapi.write(pixels) time.sleep(.13)
def loop(self): while self.is_running: self.render() octoapi.write(self.pixels) time.sleep(self.update_speed)
min1 = pixmin + pixrange * ((minutes % 10)/10.) pixels[offset+2] = self.valToRGB(min1) min2 = pixmin + pixrange * ((minutes / 10)/6.) pixels[offset+3] = self.valToRGB(min2) hour1 = pixmin + pixrange * ((hours % 10)/10.) pixels[offset+4] = self.valToRGB(hour1) hour2 = pixmin + pixrange * ((hours / 10)/1.) pixels[offset+5] = self.valToRGB(hour2) return pixels def valToRGB(self, val): if (val < 1023/4.0): return (val,val,0) elif (val < 1023/4.0*2.0): return (0,val,val) elif (val < 1023/4.0*3.0): return (val,0,val) else: return (val,val,val) if __name__ == "__main__": import octoapi import time c = Clock() while True: pix = [(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,0)] pix = c.render(pix) octoapi.write(pix) time.sleep(0.2)