def png(): from PIL import Image if request.method == 'POST': png = request.form['png'] png = png.split(",", 1)[1] im = Image.open(BytesIO(base64.b64decode(png))) im.rotate(90) if im.format == "GIF": while True: try: imageArray = [[0 for x in range(wandwidth)] for y in range(wandheight)] for y in range(wandheight): for x in range(wandwidth): imageArray[y][x] = 1 if im.getpixel( (x, y))[0] == 255 else 0 image = FlipdotImage(imageArray) im.seek(im.tell() + 1) matrix.show(image) except EOFError: break else: imageArray = [[0 for x in range(wandwidth)] for y in range(wandheight)] for y in range(wandheight): for x in range(wandwidth): imageArray[y][x] = 1 if im.getpixel( (x, y))[0] == 255 else 0 image = FlipdotImage(imageArray) matrix.show(image) return "" else: return redirect("/")
def loop(self): oldImage = FlipdotImage(self.generateClockImage()) try: while True: flipImage = FlipdotImage(self.generateClockImage()) if (self.flipdot_out and flipImage.serializeImageArray() != oldImage.serializeImageArray()): self.matrix.show(flipImage) oldImage = flipImage if self.run_once: break sleep(self.update_interval) except KeyboardInterrupt: return
def main_loop(sizex, sizey, udpHostsAndPorts=[], console_out=False, api_defaults=False, update_interval=0): if len(udpHostsAndPorts) != 0: flipdot_matrix = FlipdotMatrix(udpHostsAndPorts, (sizex, sizey)) flipdot_out = True elif api_defaults: flipdot_matrix = FlipdotMatrix(imageSize=(sizex, sizey)) flipdot_out = True else: flipdot_matrix = None flipdot_out = False pixel_matrix = generateEmptyMatrix(sizex, sizey) try: while True: pixel_matrix = step(pixel_matrix, sizex, sizey) if console_out: printToConsole(pixel_matrix, sizex, sizey) if flipdot_out: flipImage = FlipdotImage( prepareMatrixForAPI(pixel_matrix, sizex, sizey)) matrix.show(flipImage, sizex, sizey) sleep(update_interval) except KeyboardInterrupt: return
def show(pixel_matrix, flipdot_matrix, flipdot_out, console_out, sizex, sizey): if flipdot_out: flipImage = FlipdotImage( prepareMatrixForAPI(pixel_matrix, sizex, sizey)) addText(flipImage, sizex, sizey) flipdot_matrix.show(flipImage) if console_out: printToConsole(pixel_matrix, sizex, sizey)
def chess(): imageArray = [[0 for x in range(wandwidth)] for y in range(wandheight)] for y in range(wandheight): for x in range(wandwidth): imageArray[y][x] = (x + y) % 2 image = FlipdotImage(imageArray) matrix.show(image) return minipage("chess!")
def loop(self): playing = False while not self.stop: t = time() new_game = self.step() if new_game: playing = False self.ball.stop() image = self.generatePongImage() if not playing: playing = all([x.active for x in self.players]) if playing: self.ball.change_direction((1, 0)) if self.invert: pass if self.flipdot_out: flipImage = FlipdotImage(image.T) score_string = "%d - %d" % (self.players[0].score, self.players[1].score) flipImage.blitTextAtPosition(score_string, xPos=self.get_center()[0] - 2 * (len(score_string) - 1), yPos=2 * round(self.size[1] / 12)) total_score_string = "%d - %d" % (self.players[0].total_score, self.players[1].total_score) flipImage.blitTextAtPosition(total_score_string, xPos=self.get_center()[0] - 2 * (len(total_score_string) - 1), yPos=(round(self.size[1] / 12))) if not playing: if not self.players[0].active: flipImage.blitTextAtPosition( "Press Left", xPos=self.players[0].upper_right()[0] + 2, yPos=self.size[1] - self.players[0].upper_right()[1]) if not self.players[1].active: flipImage.blitTextAtPosition( "Press Left", xPos=self.players[1].lower_left()[0] - 46, yPos=self.size[1] - self.players[1].upper_right()[1]) self.flipmatrix.show(flipImage) if self.console_out: self.printImage(image) wait = (1. / self.speed) - (time() - t) if wait > 0: sleep(wait) else: print("Too slow!")
def run(self): collision = False while not collision and not self.stop: if self.pause: sleep(1. / self.speed) continue collision = self.step() image = self.generateRaceImage() if self.invert: self.invertImage(image) if self.flipdot_out: flipImage = FlipdotImage(self.transpose(image)) self.flipmatrix.show(flipImage) if self.console_out: self.printImage(image) sleep(1. / self.speed) self.lost = True