Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active February 1, 2024 21:57
Show Gist options
  • Save todbot/8c11013b3efb47c4ddbe832045b4f8f0 to your computer and use it in GitHub Desktop.
Save todbot/8c11013b3efb47c4ddbe832045b4f8f0 to your computer and use it in GitHub Desktop.
spinning sorta radar based off of John Park's CircuitPython Parsec 1 Feb 2024
import board
import displayio
import math
import time
# Set up the display
display = board.DISPLAY
# Create a blank displayio group
tilegroup = displayio.Group()
# Add the group to the display
display.show(tilegroup)
# Create a group of box bitmaps, each with a different color
num_colors = 30
palette = displayio.Palette(num_colors)
dcolor = int(255 / num_colors) # amount of color difference per box
for i in range(num_colors):
palette[i] = (dcolor*i) << 8 # e.g. 0x00ii00 just green
bitmap = displayio.Bitmap(5, 5, num_colors) # 5x5 box
bitmap.fill(i)
tile = displayio.TileGrid(bitmap, pixel_shader=palette) # stick bitmap in tilegrid
tilegroup.append(tile) # add tilegrid to group
# Set initial position and parameters for curved motion
center_x, center_y = display.width // 2, display.height // 2
angle = 0
radius = 30
while True:
# Compute new x,y position based off angle
x = center_x + radius * math.sin(angle)
y = center_y + radius * math.cos(angle)
# Update angle for next frame
angle += 0.2
# Update the highest box position (-1 = last one in list)
tilegroup[-1].x = int(x)
tilegroup[-1].y = int(y)
# move the last box positions down to older boxes
for i in range(0,num_colors-1):
tilegroup[i].x = tilegroup[i+1].x
tilegroup[i].y = tilegroup[i+1].y
# Update the display
display.refresh()
# Pause for a short time to control the speed of the animation
time.sleep(0.05)
@DJDevon3
Copy link

DJDevon3 commented Feb 1, 2024

Very pretty and smooth animation. There are plenty of applications for something like this especially on the new round RGB666 displays or even the GC9A01.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment