def cleaner(): colours = (inkyphat.RED, inkyphat.BLACK, inkyphat.WHITE) for c in enumerate(colours): inkyphat.set_border(c) for x in range(inkyphat.WIDTH): for y in range(inkyphat.HEIGHT): inkyphat.putpixel((x, y), c) inkyphat.show()
def clear_area(start_x, start_y, width, height): x = max(start_x, 0) y = max(start_y, 0) x_end = min(start_x + width, inkyphat.WIDTH - 1) y_end = min(start_y + height, inkyphat.HEIGHT - 1) for i in range(x, x_end): for j in range(y, y_end): inkyphat.putpixel((i, j), inkyphat.WHITE)
def render(display): for x in range(inkyphat.WIDTH): for y in range(inkyphat.HEIGHT): inkyphat.putpixel((x, y), 0) for x in range(inkyphat.WIDTH): for y in range(inkyphat.HEIGHT): try: inkyphat.putpixel((x, y), display[y][x]) except (IndexError): pass inkyphat.show()
def iclearNow(col): # claer inkyphat and refresh for x in range(212): for y in range(104): inkyphat.putpixel((x, y), col) inkyphat.show()
def iclear(col): # Clear inkyphat but don't refresh for x in range(212): for y in range(104): inkyphat.putpixel((x, y), col)
if len(sys.argv) < 2: print("""Usage: {} <colour> <number of cycles> Valid colours: red, yellow, black """.format(sys.argv[0])) sys.exit(0) colour = sys.argv[1].lower() inkyphat.set_colour(colour) if len(sys.argv) > 2: cycles = int(sys.argv[2]) else: cycles = 3 colours = (inkyphat.RED, inkyphat.BLACK, inkyphat.WHITE) colour_names = (colour, "black", "white") for i in range(cycles): print("Cleaning cycle %i\n" % (i + 1)) for j, c in enumerate(colours): print("- updating with %s" % colour_names[j]) inkyphat.set_border(c) for x in range(inkyphat.WIDTH): for y in range(inkyphat.HEIGHT): inkyphat.putpixel((x, y), c) inkyphat.show() time.sleep(1) print("\n") print("Cleaning complete!")