improve examples

This commit is contained in:
Jeff Epler 2025-01-15 10:19:26 -06:00
parent 66c5bf124d
commit aeab803caf
2 changed files with 46 additions and 4 deletions

29
examples/playframes.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/python3
"""
Display a series of 64x32 PNG images as fast as possible
Run like this:
$ python playframes.py "/path/to/images/*.png"
The image files are sorted and then played repeatedly until interrupted with ctrl-c.
"""
import glob
import sys
import adafruit_raspberry_pi5_piomatter
import numpy as np
import PIL.Image as Image
images = sorted(glob.glob(sys.argv[1]))
geometry = adafruit_raspberry_pi5_piomatter.Geometry(width=64, height=32, n_addr_lines=4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.Normal)
framebuffer = np.asarray(Image.open(images[0])) + 0 # Make a mutable copy
matrix = adafruit_raspberry_pi5_piomatter.AdafruitMatrixBonnetRGB888Packed(framebuffer, geometry)
while True:
for i in images:
print(i)
framebuffer[:] = np.asarray(Image.open(i))
matrix.show()

View file

@ -1,12 +1,25 @@
#!/usr/bin/python3
"""
Display a static 64x64 image
This assumes two 64x32 matrix panels are hooked together in the "serpentine" configuration.
Run like this:
$ python simpletest.py
The image is displayed until the user hits enter to exit.
"""
import pathlib
import adafruit_raspberry_pi5_piomatter
import numpy as np
import PIL.Image as Image
g = adafruit_raspberry_pi5_piomatter.Geometry(64, 64, 4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.Normal)
arr = np.asarray(Image.open(pathlib.Path(__file__).parent / "blinka64x64.png"))
m = adafruit_raspberry_pi5_piomatter.AdafruitMatrixBonnetRGB888Packed(arr, g)
m.show()
geometry = adafruit_raspberry_pi5_piomatter.Geometry(width=64, height=64, n_addr_lines=4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.Normal)
framebuffer = np.asarray(Image.open(pathlib.Path(__file__).parent / "blinka64x64.png"))
matrix = adafruit_raspberry_pi5_piomatter.AdafruitMatrixBonnetRGB888Packed(framebuffer, geometry)
matrix.show()
input("Hit enter to exit")