As always, you need to activate the virtual environment before running the example. If you haven't already then activate it like this.
source ~/venvs/blinka_venv/bin/activate
Next you can run the play_gif.py script.
python play_gif.py
The code for this example is embedded below. You can download it, or copy/paste the text into a file.
#!/usr/bin/python3 """ Display an animated gif Run like this: $ python play_gif.py The animated gif is played repeatedly until interrupted with ctrl-c. """ import time import numpy as np import PIL.Image as Image import adafruit_blinka_raspberry_pi5_piomatter as piomatter width = 64 height = 32 gif_file = "nyan.gif" canvas = Image.new('RGB', (width, height), (0, 0, 0)) geometry = piomatter.Geometry(width=width, height=height, n_addr_lines=4, rotation=piomatter.Orientation.Normal) framebuffer = np.asarray(canvas) + 0 # Make a mutable copy matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=piomatter.Pinout.AdafruitMatrixBonnet, framebuffer=framebuffer, geometry=geometry) with Image.open(gif_file) as img: print(f"frames: {img.n_frames}") while True: for i in range(img.n_frames): img.seek(i) canvas.paste(img, (0,0)) framebuffer[:] = np.asarray(canvas) matrix.show() time.sleep(0.1)
Page last edited February 05, 2025
Text editor powered by tinymce.