Last active
June 19, 2023 03:39
-
-
Save todbot/e45bf9c680c4441cae11347351d59b71 to your computer and use it in GitHub Desktop.
Animated Star Wars targeting computer for CircuitPython
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
# sw_targeting_computer_code.py -- animated targeting computer for CircuitPython | |
# 4 May 2022 - @todbot / Tod Kurt | |
# # Uses one background image and two tilegrid animations | |
import time | |
import board | |
import displayio | |
display = board.DISPLAY | |
maingroup = displayio.Group() | |
display.show(maingroup) # put main group on display, everything goes in maingroup | |
# targetting computer background | |
bitmap = displayio.OnDiskBitmap(open("/imgs/swtc_bg.bmp", "rb")) | |
pal = bitmap.pixel_shader | |
bg = displayio.TileGrid(bitmap, pixel_shader=pal) | |
maingroup.append(bg) | |
# main animated grid | |
bitmap = displayio.OnDiskBitmap(open("/imgs/swtc_grid_tile.bmp","rb")) | |
pal = bitmap.pixel_shader | |
tc = displayio.TileGrid(bitmap, pixel_shader=pal, x=65, y=16, | |
width=1, height=1, tile_width=120, tile_height=95) | |
maingroup.append(tc) | |
# animated lights on lower left | |
bitmap = displayio.OnDiskBitmap(open("/imgs/swtc_lights_tile.bmp","rb")) | |
pal = bitmap.pixel_shader | |
lights = displayio.TileGrid(bitmap, pixel_shader=pal, x=-30, y=75, | |
width=1, height=1, tile_width=90, tile_height=41) | |
maingroup.append(lights) | |
i=0 | |
while True: | |
print("stay on target", i) | |
tc[0] = i # animate the targetting computer grid | |
lights[0] = i # animate the lights | |
i=(i+1) % 9 | |
time.sleep(0.1) |
Here's a demo of it in action
swt_demo1a.mp4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These are the images used. Convert them to BMPs with ImageMagick with these commands:
Then make a directory called "imgs" in CIRCUITPY and copy the resulting BMP files to CIRCUITPY/imgs.