Last active
September 18, 2018 19:39
-
-
Save gregtap/0f5aa7d92566100112cdecc526f1c404 to your computer and use it in GitHub Desktop.
sprite led
This file contains hidden or 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
from PIL import Image | |
from PIL import ImageDraw | |
import time | |
from rgbmatrix import RGBMatrix, RGBMatrixOptions | |
# Configuration for the matrix | |
options = RGBMatrixOptions() | |
options.rows = 32 | |
options.chain_length = 6 | |
options.parallel = 1 | |
# If you have an Adafruit HAT: 'adafruit-hat' | |
options.hardware_mapping = 'regular' | |
matrix = RGBMatrix(options=options) | |
image = Image.open('sprites.ppm').convert('RGB') | |
double_buffer = matrix.CreateFrameCanvas() | |
img_width, img_height = image.size | |
# let's scroll | |
xpos = 0 | |
area1 = (0, 0, 25, 40) | |
i1 = image.crop(area1) | |
area2 = (25, 0, 50, 40) | |
i2 = image.crop(area2) | |
area3 = (50, 0, 75, 40) | |
i3 = image.crop(area3) | |
area4 = (75, 0, 99, 40) | |
i4 = image.crop(area4) | |
frames = [i1, i2, i3, i4] | |
i = 0 | |
frame_i = 0 | |
while True: | |
xpos += 1 | |
if (xpos > img_width): | |
xpos = 0 | |
double_buffer.Fill(0, 172, 255) | |
double_buffer.SetImage(frames[frame_i], 50) | |
if (i % 5 == 0): | |
frame_i += 1 | |
if frame_i % len(frames) == 0: | |
frame_i = 0 | |
double_buffer = matrix.SwapOnVSync(double_buffer) | |
time.sleep(0.05) | |
i += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment