Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Animated Star Wars targeting computer for CircuitPython
# 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)
@todbot
Copy link
Author

todbot commented May 4, 2022

These are the images used. Convert them to BMPs with ImageMagick with these commands:

convert swtc_bg.png -type palette -colors 256 -compress None BMP3:swtc_bg.bmp
convert swtc_grid_tile.png -type palette -colors 256 -compress None BMP3:swtc_grid_tile.bmp
convert swtc_lights_tile.png -type palette -colors 256 -compress None BMP3:swtc_lights_tile.bmp

Then make a directory called "imgs" in CIRCUITPY and copy the resulting BMP files to CIRCUITPY/imgs.

swtc_bg
swtc_grid_tile
swtc_lights_tile

@todbot
Copy link
Author

todbot commented May 4, 2022

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