# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries # SPDX-FileCopyrightText: Adapted from Phil B.'s 16bit_hello Arduino Code # SPDX-License-Identifier: MIT # Updated 2026 at Iffy Books, wtfpl import os import gc import digitalio import time import displayio import picodvi import board import framebufferio import terminalio import simpleio #from adafruit_bitmap_font import bitmap_font #from adafruit_display_text import label, wrap_text_to_lines from adafruit_display_shapes.rect import Rect import random # pin defs for DVI Sock displayio.release_displays() fb = picodvi.Framebuffer(320, 240, clk_dp=board.GP14, clk_dn=board.GP15, red_dp=board.GP12, red_dn=board.GP13, green_dp=board.GP18, green_dn=board.GP19, blue_dp=board.GP16, blue_dn=board.GP17, color_depth=8) display = framebufferio.FramebufferDisplay(fb) #red = 0xff0000 #yellow = 0xcccc00 #orange = 0xff5500 #blue = 0x0000ff #pink = 0xff00ff #purple = 0x5500ff #white = 0xffffff #green = 0x00ff00 #aqua = 0x125690 #black = 0x000000 colors=[0x02488c, 0xca4741, 0x2a8947, 0x9ba7b7, 0xba4f6e, 0xa36eed, 0xa8135e, 0xa20f5f, 0xcdbbcf, 0x86d986, 0xdf09e5, 0xaed480, 0xf6f8fa, 0xf2a5c9, 0xa196d4, 0x3505ef, 0x443f54, 0x5cd9a9,0x14c161, 0x44828f, 0x72da5c, 0x856f8a, 0x6d8cfe, 0x67ac71, 0xd2e464, 0xe83a89, 0x077afc, 0xcb3282, 0x6d2e2a, 0x854d89, 0xba5a81, 0x37cf81, 0xbc67b7, 0xb70e25, 0xae8e16, 0x32fe59, 0xe44431, 0xde34ce, 0xc1fde4, 0x768275, 0x5d42d1, 0x14288b, 0xba3196, 0x981e4c, 0x835146, 0xb98a7f, 0xe849a7, 0x4b450a, 0x59ec5e] # The GPIO pins we'll use for our keys gpio_pins = [board.GP5,board.GP10] key_pins = [] for pin in gpio_pins: key_pin = digitalio.DigitalInOut(pin) key_pin.direction = digitalio.Direction.INPUT key_pin.pull = digitalio.Pull.UP key_pins.append(key_pin) palette = displayio.Palette(3) palette[0] = 0x000000 # black palette[1] = white palette[2] = yellow palette.make_transparent(0) group = displayio.Group() def clean_up(group_name): for _ in range(len(group_name)): group_name.pop() gc.collect() height = random.randint(18,19) gc.collect() size = 40 width = size height = size num_cols = 6 rect_counter = 0 while True: for key_pin in key_pins: if not key_pin.value: # Is the key pressed? # Action for first key if key_pin == key_pins[0]: if rect_counter < 40: y = random.randint(40,320-40) x = random.randint(40,240-40) tempcolor=random.choice(colors) print(tempcolor) rect = Rect(x, y, width+random.randint(2,40), height+random.randint(2,40), stroke = 2, fill=tempcolor, outline = black) group.append(rect) display.root_group = group time.sleep(0.1) gc.collect() rect_counter+=1 else: clean_up(group) try: del rect except: pass gc.collect() rect_counter=0 elif key_pin == key_pins[1]: clean_up(group) try: del rect except: pass gc.collect()