many works
This commit is contained in:
parent
9bd764579a
commit
c937450f92
7 changed files with 151 additions and 36 deletions
|
|
@ -1,24 +1,51 @@
|
|||
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||
from PIL import ImageFont, Image
|
||||
|
||||
# Das Bild nur speichern. Nicht die LED-Matrix ansteuern.
|
||||
DEV = True
|
||||
DEV = False
|
||||
#DEV = True
|
||||
|
||||
if not DEV:
|
||||
options = RGBMatrixOptions()
|
||||
options.rows = 64
|
||||
options.cols = 64
|
||||
options.chain_length = 2
|
||||
options.parallel = 1
|
||||
options.hardware_mapping = 'regular' # change if using Adafruit HAT, e.g. 'adafruit-hat'
|
||||
options.gpio_slowdown = 4 # try 2, 4, or even 5
|
||||
options.disable_hardware_pulsing = True
|
||||
matrix = None
|
||||
|
||||
matrix = RGBMatrix(options=options)
|
||||
matrix_width = 64 * options.chain_length
|
||||
matrix_height = 64
|
||||
MATRIX_HEIGHT = 64
|
||||
MATRIX_WIDTH = 64
|
||||
NUMBER_OF_PANELS = 4
|
||||
|
||||
class MyMatrix:
|
||||
def __init__(self):
|
||||
#self.matrix_width = options.cols * options.chain_length
|
||||
#self.matrix_height = options.rows
|
||||
|
||||
try:
|
||||
self.font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf", 18)
|
||||
except IOError:
|
||||
self.font = ImageFont.load_default()
|
||||
|
||||
if not DEV:
|
||||
options = RGBMatrixOptions()
|
||||
options.rows = MATRIX_HEIGHT
|
||||
options.cols = MATRIX_WIDTH
|
||||
options.chain_length = NUMBER_OF_PANELS
|
||||
options.parallel = 1
|
||||
options.hardware_mapping = 'regular' # change if using Adafruit HAT, e.g. 'adafruit-hat'
|
||||
options.gpio_slowdown = 5 # try 2, 4, or even 5
|
||||
options.disable_hardware_pulsing = True
|
||||
options.drop_privileges = False
|
||||
|
||||
self.matrix = RGBMatrix(options=options)
|
||||
|
||||
def show(self, image):
|
||||
"""Save the image to disk in DEV mode. Or send it to the LED matrix panel."""
|
||||
if DEV:
|
||||
image.save('image.png')
|
||||
elif matrix:
|
||||
self.matrix.SetImage(image)
|
||||
else:
|
||||
print("Not in dev mode. And matrix not initialized.")
|
||||
|
||||
def buffer(self):
|
||||
"""Get an image buffer with the right dimensions"""
|
||||
return Image.new("RGB", (MATRIX_WIDTH * NUMBER_OF_PANELS, MATRIX_HEIGHT))
|
||||
|
||||
matrix = MyMatrix()
|
||||
|
||||
def do(image):
|
||||
if DEV:
|
||||
image.save('image.png')
|
||||
else:
|
||||
matrix.SetImage(image)
|
||||
|
|
|
|||
24
lib/helpers.py
Normal file
24
lib/helpers.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
def triangle(image_draw, offset_x, offset_y, direction, width, height):
|
||||
"""Show triangle. Direction is -1 (down) or 1 (up)."""
|
||||
points = []
|
||||
color = None
|
||||
|
||||
if direction==1:
|
||||
points = [
|
||||
(width/2, 0), # n
|
||||
(0, height), # sw
|
||||
(width, height) # se
|
||||
]
|
||||
color = (0, 255, 0) # green
|
||||
else:
|
||||
points = [
|
||||
(width/2, height), # s
|
||||
(0, 0), # nw
|
||||
(width,0) # ne
|
||||
]
|
||||
color = (255, 0, 0) # red
|
||||
|
||||
# Draw a filled green triangle
|
||||
points = [(x+offset_x, y+offset_y) for (x,y) in points]
|
||||
image_draw.polygon(points, fill=color)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue