"""16x16 matrix-style rain animation.""" from machine import Pin import neopixel import random import time from panel16_utils import PANEL_H, PANEL_W, clamp8, xy_to_index np = neopixel.NeoPixel(Pin(4), PANEL_W * PANEL_H) rng = random.Random(42) heads = [rng.randrange(-PANEL_H, 0) for _ in range(PANEL_W)] for _frame in range(320): for y in range(PANEL_H): for x in range(PANEL_W): np[xy_to_index(x, y)] = (0, 0, 0) for x in range(PANEL_W): heads[x] += 1 if heads[x] > PANEL_H + 6: heads[x] = rng.randrange(-PANEL_H, 0) head_y = heads[x] for tail in range(8): y = head_y - tail if 0 <= y < PANEL_H: brightness = clamp8(255 - tail * 36) np[xy_to_index(x, y)] = (0, brightness, 0) np.write() time.sleep(0.045) np.fill((0, 0, 0)) np.write()