def _play_frame(self): ctime = time.time() * 1000 frames = [animation.frame(ctime) for animation in self._animations] if self.toggle: # preview layers stream = {'previews': []} for i, anim in enumerate(self._animations): pf = [np.round(band * 255.0) for band in frames[i].getrgba()] pixles = [] for y in range(self._h): for x in range(self._w): pixles.append("rgba(%d,%d,%d,%d)" % (pf[0][y][x], pf[1][y][x], pf[2][y][x], pf[3][y][x])) stream['previews'].append(pixles) self._websocket.write_message(simplejson.dumps(stream)) self.toggle = False else: self.toggle = True outframe = self._bg\ .blend(frames[3], opacity=self._animations[3].opacity, blendfunc=self._animations[3].blendmode)\ .blend(frames[2], opacity=self._animations[2].opacity, blendfunc=self._animations[2].blendmode)\ .blend(frames[1], opacity=self._animations[1].opacity, blendfunc=self._animations[1].blendmode)\ .blend(frames[0], opacity=self._animations[0].opacity, blendfunc=self._animations[0].blendmode) n = [ np.round(band * 255.0).astype(np.ubyte) for band in outframe.getrgba() ] """ for y in range(self._h): for x in range(self._w): stream['final'].append("rgba(%d,%d,%d,%d)" % (n[0][y][x], n[1][y][x], n[2][y][x], n[3][y][x])) """ fdata = [] for y in range(self._h): for x in range(self._w): r = n[0][y][x] g = n[1][y][x] b = n[2][y][x] color = correct_rgb((r, g, b)) fdata.extend([0xFF, self._mapping[y * self._w + x]]) fdata.extend(color) self._serial_device.write("".join([chr(v) for v in fdata]))
def _play_frame(self): ctime = time.time() * 1000 frames = [animation.frame(ctime) for animation in self._animations] if self.toggle: # preview layers stream = { 'previews': [] } for i, anim in enumerate(self._animations): pf = [np.round(band * 255.0) for band in frames[i].getrgba()] pixles = [] for y in range(self._h): for x in range(self._w): pixles.append("rgba(%d,%d,%d,%d)" % (pf[0][y][x], pf[1][y][x], pf[2][y][x], pf[3][y][x])) stream['previews'].append(pixles) self._websocket.write_message(simplejson.dumps(stream)) self.toggle = False else: self.toggle = True outframe = self._bg\ .blend(frames[3], opacity=self._animations[3].opacity, blendfunc=self._animations[3].blendmode)\ .blend(frames[2], opacity=self._animations[2].opacity, blendfunc=self._animations[2].blendmode)\ .blend(frames[1], opacity=self._animations[1].opacity, blendfunc=self._animations[1].blendmode)\ .blend(frames[0], opacity=self._animations[0].opacity, blendfunc=self._animations[0].blendmode) n = [np.round(band * 255.0).astype(np.ubyte) for band in outframe.getrgba()] """ for y in range(self._h): for x in range(self._w): stream['final'].append("rgba(%d,%d,%d,%d)" % (n[0][y][x], n[1][y][x], n[2][y][x], n[3][y][x])) """ fdata = [] for y in range(self._h): for x in range(self._w): r = n[0][y][x] g = n[1][y][x] b = n[2][y][x] color = correct_rgb((r, g, b)) fdata.extend([0xFF, self._mapping[y * self._w + x]]) fdata.extend(color) self._serial_device.write("".join([chr(v) for v in fdata]))
def send(data, serial_device): pindex = 0 fdata = [] for y in range(h): for x in range(w): r = data[pindex * 3] g = data[pindex * 3 + 1] b = data[pindex * 3 + 2] color = correct_rgb((r, g, b)) fdata.extend([0xFF, mapping[y * w + x]]) fdata.extend(color) pindex += 1 serial_device.write("".join([chr(v) for v in fdata]))
def _dmxdata(self, data): pindex = 0 fdata = [] for y in range(self._h): for x in range(self._w): r = data[pindex * 3] g = data[pindex * 3 + 1] b = data[pindex * 3 + 2] color = correct_rgb((r, g, b)) fdata.extend([0xFF, self._mapping[y * self._w + x]]) fdata.extend(color) pindex += 1 self._serial_device.write("".join([chr(v) for v in fdata]))