rpi-rgb-led-matrix/python/samples/image-scroller.py
2016-08-28 17:50:05 -07:00

38 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python
import time
from samplebase import SampleBase
from rgbmatrix import RGBMatrix
from PIL import Image
class ImageScroller(SampleBase):
def __init__(self, image_file, *args, **kwargs):
super(ImageScroller, self).__init__(*args, **kwargs)
self.image = Image.open(image_file)
def Run(self):
self.image.resize((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
doubleBuffer = self.matrix.CreateFrameCanvas()
img_width, img_height = self.image.size
# let's scroll
xpos = 0
while True:
xpos += 1
if (xpos > img_width):
xpos = 0
doubleBuffer.SetImage(self.image, -xpos)
doubleBuffer.SetImage(self.image, -xpos + img_width)
doubleBuffer = self.matrix.SwapOnVSync(doubleBuffer)
time.sleep(0.01)
# Main function
# e.g. call with
# sudo ./image-scroller.py --chain=4
# if you have a chain of four
if __name__ == "__main__":
scroller = ImageScroller(image_file = "../../examples-api-use/runtext.ppm")
if (not scroller.process()):
scroller.print_help()