Commit fd3d06e9 authored by Michael Murtaugh's avatar Michael Murtaugh

more sample matrix code

parent 01ae1d6a
#!/usr/bin/env python
import time
from samplebase import SampleBase
from PIL import Image
from PIL import ImageFont, ImageDraw
import sys
import argparse
from BdfFontFile import BdfFontFile
class ImageScroller(SampleBase):
def __init__(self, *args, **kwargs):
super(ImageScroller, self).__init__(*args, **kwargs)
# self.parser.add_argument("-i", "--image", help="The image to display", default="../../../examples-api-use/runtext.ppm")
self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!")
self.parser.add_argument("--pad", type=argparse.FileType("r"), default="../constantcodeofconduct2.etherpad")
self.parser.add_argument("--padname", default="constantcodeofconduct2")
self.parser.add_argument("--font", default="fonts/9x18.bdf")
def run(self):
# if not 'image' in self.__dict__:
# self.image = Image.open(self.args.image).convert('RGB')
# self.image.resize((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
padname = self.args.padname
data = json.load(self.args.pad)
pad_data = data["pad:{0}".format(padname)]
last_rev = pad_data['head']
text = "\n"
for r in range(0, last_rev+1):
d = data["pad:{0}:revs:{1}".format(padname, r)]
cs = changeset_parse(d['changeset'])
text, linepos, charpos = perform_changeset_curline(text, cs)
lines = text.splitlines()
if charpos == 0 and linepos > 0:
line = lines[linepos-1]
charpos = len(line)
else:
line = lines[linepos]
pre, post = line[:charpos], line[charpos:]
pre = pre[-40:]
post = post[:40]
sys.stdout.write("\r{0}|{1}{2}".format(pre, post, " "*64))
sys.stdout.flush()
sleep(0.25)
self.image = Image.new("RGB", (self.matrix.width * 2, self.matrix.height), (0,0,0))
draw = ImageDraw.ImageDraw(self.image)
font = ImageFont.load(self.args.font)
draw.text((10, 10), "hello", font=font)
double_buffer = 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
double_buffer.SetImage(self.image, -xpos)
# double_buffer.SetImage(self.image, -xpos + img_width)
double_buffer = self.matrix.SwapOnVSync(double_buffer)
# time.sleep(0.01)
time.sleep(0.025)
# Main function
# e.g. call with
# sudo ./image-scroller.py --chain=4
# if you have a chain of four
if __name__ == "__main__":
image_scroller = ImageScroller()
if (not image_scroller.process()):
image_scroller.print_help()
#!/usr/bin/env python
import time
from samplebase import SampleBase
from PIL import Image
class ImageScroller(SampleBase):
def __init__(self, *args, **kwargs):
super(ImageScroller, self).__init__(*args, **kwargs)
self.parser.add_argument("-i", "--image", help="The image to display", default="../../../examples-api-use/runtext.ppm")
def run(self):
if not 'image' in self.__dict__:
self.image = Image.open(self.args.image).convert('RGB')
self.image.resize((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
double_buffer = 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
double_buffer.SetImage(self.image, -xpos)
# double_buffer.SetImage(self.image, -xpos + img_width)
double_buffer = self.matrix.SwapOnVSync(double_buffer)
# time.sleep(0.01)
time.sleep(0.1)
# Main function
# e.g. call with
# sudo ./image-scroller.py --chain=4
# if you have a chain of four
if __name__ == "__main__":
image_scroller = ImageScroller()
if (not image_scroller.process()):
image_scroller.print_help()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment