Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Created December 6, 2021 22:14
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/267929050fb5875dd9e0f316e6b0945e to your computer and use it in GitHub Desktop.
Save rsbohn/267929050fb5875dd9e0f316e6b0945e to your computer and use it in GitHub Desktop.
another displayio demo
# SPDX-FileCopyrightText: Copyright (c) 2021 Randall Bohn (dexter)
#
# SPDX-License-Identifier: MIT
"""snowflakes"""
# like bubbles but they fall from they sky
# 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
display = board.DISPLAY
splash = displayio.Group()
display.show(splash)
september = [fancy.CRGB(255,0,0), fancy.CRGB(255,240,0), fancy.CRGB(128,255,0)]
ice = [fancy.CRGB(255,255,255), fancy.CRGB(240,240,240),
fancy.CRGB(255,255,255), fancy.CRGB(128,255,255)]
snow = ice[:2]
ncolors=64
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
palette = displayio.Palette(ncolors)
fill_palette(palette, snow)
def stripe(palette, width, height):
n = len(palette)
bitmap = displayio.Bitmap(width, height, n)
for x in range(width):
for y in range(height):
bitmap[x,y] = int(n * x/width)
return bitmap
bitmap = stripe(palette, display.width, 16)
tg = displayio.TileGrid(bitmap, pixel_shader=palette)
bubbles = displayio.Group()
for _ in range(24):
x = random.randrange(12,display.width-12)
y = random.randrange(0,display.height)
r = random.randrange(2,4)
color=random.choice(palette)
#bubbles.append(Circle(x,y,r,fill=0,stroke=1,outline=color))
bubbles.append(Circle(x,y,r,fill=color))
splash.append(bubbles)
splash.append(tg)
def herd(group):
for shape in group:
shape.x += random.randint(-2,2)
if shape.x < 9: shape.x = display.width - 18
if shape.x > display.width - 9: shape.x = 18
shape.y += random.randint(0,5)
if shape.y > display.height + 6: shape.y = -12
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