Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active May 27, 2023 07:55
Show Gist options
  • Save todbot/99ee476b600e19da7793a94155ff3805 to your computer and use it in GitHub Desktop.
Save todbot/99ee476b600e19da7793a94155ff3805 to your computer and use it in GitHub Desktop.
Show a bunch of emojis from a sprite sheet in CircuitPython
# emoji_flipper.py - show a bunch of emojis from a sprite sheet
# 23 Jun 2022 - @todbot / Tod Kurt
import time
import board
import displayio
sprite_fname = "emoji_spritesheet_27x7_28x28.bmp"
sprite_cnt = 27*7
sprite_w,sprite_h = 28,28
sprite_sheet = displayio.OnDiskBitmap(open(sprite_fname, "rb"))
sprite_palette = sprite_sheet.pixel_shader
# this below will be faster than OnDiskBitmap, but not all boards have enough RAM
# import adafruit_imageload
# sprite_sheet, sprite_palette = adafruit_imageload.load(sprite_fname)
sprite_palette.make_transparent(0) # make background color transparent
sprite = displayio.TileGrid(sprite_sheet, pixel_shader=sprite_palette,
width = 1, height = 1,
tile_width = sprite_w, tile_height = sprite_h)
display = board.DISPLAY # our board has built-in display
maingroup = displayio.Group(scale=4) # make 4x big
maingroup.append(sprite)
display.show(maingroup)
sprite_index = 0 # where in the sprite sheet we currently are
while True:
sprite[0] = sprite_index
sprite_index = (sprite_index + 1) % sprite_cnt
time.sleep(0.1)
@todbot
Copy link
Author

todbot commented Jun 24, 2022

Some demos:

emoji_flipper_demo1nohdr.mp4

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