def main(args): from optparse import OptionParser optp = OptionParser(usage="%prog [options] [address]") optp.add_option("-p", "--player", help="Set preferred player (0-5)", metavar="PLAYER", type="int", default=None) optp.add_option("-d", "--direct-input", help="Get more direct input", action="store_false", default=True) optp.add_option("--priority", help="Change priority, default is 2", metavar="PRIORITY", type="int", default=2) (options, args) = optp.parse_args() matrix = LedMatrix(args[0] if args else None) try: matrix.change_priority(options.priority) game = SnakeGame(matrix, options.direct_input, options.player) game.run() finally: matrix.close()
def main(args): from optparse import OptionParser optp = OptionParser() optp.add_option("-s", "--fade_steps", help="Set color fading speed in steps between colors", metavar="FADE_STEPS", type="int", default=40) optp.add_option("--priority", help="Apply the given priority to the connection", metavar="PRIORITY", type="int") optp.add_option( "-c", "--color", help="Add a color (in hex, e.g. ff0000) to the color fading", action="append", metavar="COLOR") optp.add_option("-b", "--background", help="Set background color", metavar="COLOR") (options, args) = optp.parse_args() if options.color != None: colors = [parse_color(color_str) for color_str in options.color] else: colors = DEF_COLORS if options.background != None: background = parse_color(options.background) else: background = DEF_BACK matrix = LedMatrix() if options.priority != None: matrix.change_priority(options.priority) if len(args) < 1: text = "<<</>>" else: text = u' '.join(arg.decode("utf-8") for arg in args) try: FadingText(matrix, text, options.fade_steps, colors, background=background).endless() finally: matrix.close()
def main(args): from optparse import OptionParser optp = OptionParser() optp.add_option("-s", "--fade_steps", help="Set color fading speed in steps between colors", metavar="FADE_STEPS", type="int", default=40) optp.add_option("--priority", help="Apply the given priority to the connection", metavar="PRIORITY", type="int") optp.add_option("-c", "--color", help="Add a color (in hex, e.g. ff0000) to the color fading", action="append", metavar="COLOR") optp.add_option("-b", "--background", help="Set background color", metavar="COLOR") (options, args) = optp.parse_args() if options.color != None: colors = [parse_color(color_str) for color_str in options.color] else: colors = DEF_COLORS if options.background != None: background = parse_color(options.background) else: background = DEF_BACK matrix = LedMatrix() if options.priority != None: matrix.change_priority(options.priority) if len(args) < 1: text = "<<</>>" else: text = u' '.join(arg.decode("utf-8") for arg in args) try: FadingText(matrix, text, options.fade_steps, colors, background=background).endless() finally: matrix.close()
intensity = math.sqrt((rad - dist) / rad) * 2 * max_intensity intensity = min(intensity, max_intensity) # not sending if pixel already at that state if field[field_pos] != intensity: # marking pixel as dirty field[field_pos] = intensity # finally painting matrix.send_pixel((x,y), (intensity, intensity, 0x00)) if not painted and field[field_pos]: # clear formerly painted and no longer used pixels field[field_pos] = False matrix.send_pixel((x,y), (0x00, 0x00, 0x00)) # move forward self.pos += 1 # are we finished? return pos < width matrix = LedMatrix() pacman = Pacman(matrix) try: const_loop(pacman.step, 0.2) finally: matrix.close()
if old_field[n % width][m % height]: prox += 1 if old_field[x][y]: prox -= 1 if prox < 2: print "lonely ", prox self.die(x, y) elif prox > 3: print "crowded ", prox self.die(x, y) else: self.survive(x, y) elif prox == 3: self.create(x, y) return True matrix = LedMatrix() try: matrix.send_clear() game = GameOfLife(matrix) game.load(sys.argv[1]) const_loop(game.step, 0.2) finally: matrix.close()