Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Created December 5, 2021 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsbohn/7da807b2b10484d82b590dca634f6f95 to your computer and use it in GitHub Desktop.
Save rsbohn/7da807b2b10484d82b590dca634f6f95 to your computer and use it in GitHub Desktop.
Put bubbles on your face (LED Glasses)
# SPDX-FileCopyrightText: Copyright (c) 2021 Randall Bohn (dexter)
#
# SPDX-License-Identifier: MIT
"""Bubbles on your face (LED Glasses)"""
# circup install adafruit_display_shapes
# circup install adafruit_fancyled
import random
import time
import displayio
from adafruit_display_shapes.circle import Circle
import adafruit_fancyled.adafruit_fancyled as fancy
import board
show_palette = True
if "display" in dir(board):
display = board.DISPLAY
else:
# LED Glasses
import is31fl3741
import framebufferio
import busio
#
from map import glassesmatrix_ledmap
show_palette = False
displayio.release_displays()
i2c = busio.I2C(board.SCL, board.SDA, frequency=10000000)
frame = is31fl3741.IS31FL3741(
width=54, height=15,
i2c=i2c, scale=True, gamma=True,
mapping=glassesmatrix_ledmap)
frame.brightness=0.2
display = framebufferio.FramebufferDisplay(frame, auto_refresh=True)
splash = displayio.Group()
display.show(splash)
hotwheel = [
fancy.CRGB(32,0,0),
fancy.CRGB(240,0,0),
fancy.CRGB(32,240,0),
fancy.CRGB(24,24,255),
fancy.CRGB(128,255,240)]
ncolors=64
spectrum = displayio.Palette(ncolors)
def fill_palette(palette, gradient):
n = len(palette)
for c in range(n):
color = fancy.palette_lookup(gradient, c/n)
palette[c] = color.pack()
return palette
fill_palette(spectrum, hotwheel)
# make a bitmap to display colors in spectrum
if show_palette:
bitmap = displayio.Bitmap(ncolors,24, ncolors)
for x in range(ncolors):
for y in range(24):
bitmap[x,y]=x
tg = displayio.TileGrid(bitmap, pixel_shader=spectrum)
splash.append(tg)
bubbles = displayio.Group()
for _ in range(24):
x = random.randrange(0,display.width)
y = random.randrange(0,display.height)
r = random.randrange(4,8)
color=random.choice(spectrum)
#bubbles.append(Circle(x,y,r,fill=0,stroke=1,outline=color))
bubbles.append(Circle(x,y,r,fill=color))
splash.append(bubbles)
def herd(group):
"Do bubbles travel in herds?"
for shape in group:
shape.x += random.randint(-2,2)
if shape.x < -8: shape.x = display.width + 3
if shape.x > display.width + 8: shape.x = -3
shape.y += random.randint(-2,0)
if shape.y < -9: shape.y = display.height + 26
# wait for a keystroke on the console
# You could also use `while True:`
from supervisor import runtime as RT
while not RT.serial_bytes_available:
time.sleep(0.05)
herd(bubbles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment