Created
December 4, 2021 15:45
-
-
Save rsbohn/a76ffcd0e90504f6bb8b137c7da9dbdb to your computer and use it in GitHub Desktop.
another displayio demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: Copyright (c) 2021 Randall Bohn (dexter) | |
# | |
# SPDX-License-Identifier: MIT | |
"""Bubbles""" | |
# circup install adafruit_display_shapes | |
# circup install adafruit_fancyled | |
import random | |
import time | |
import displayio | |
import framebufferio | |
import videocore | |
from adafruit_display_shapes.circle import Circle | |
import adafruit_fancyled.adafruit_fancyled as fancy | |
# broadcom HDMI display on raspberry pi zero 2 W | |
displayio.release_displays() | |
fb = videocore.Framebuffer(1920//2, 1080//2) | |
display = framebufferio.FramebufferDisplay(fb) | |
#display.rotation=270 | |
splash = displayio.Group() | |
display.show(splash) | |
hotwheel = [ | |
fancy.CRGB(32,0,0), | |
fancy.CRGB(240,0,0), | |
fancy.CRGB(240,240,0), | |
fancy.CRGB(24,24,255), | |
fancy.CRGB(128,255,240)] | |
ncolors=64 | |
spectrum = displayio.Palette(ncolors) | |
for c in range(ncolors): | |
color = fancy.palette_lookup(hotwheel, c/ncolors) | |
spectrum[c] = color.pack() | |
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(128,256) | |
y = random.randrange(0,display.height) | |
r = random.randrange(8,24) | |
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): | |
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(-5,0) | |
if shape.y < -9: shape.y = display.height + 6 | |
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