parameterize quote scroller
This commit is contained in:
parent
53e580e404
commit
cc110b3ce5
1 changed files with 13 additions and 4 deletions
|
|
@ -4,6 +4,15 @@ import adafruit_raspberry_pi5_piomatter
|
|||
import numpy as np
|
||||
import time
|
||||
|
||||
|
||||
xoffset = 0
|
||||
yoffset = 0
|
||||
|
||||
|
||||
width = 128
|
||||
height = 64
|
||||
|
||||
|
||||
# Load the font
|
||||
font = ImageFont.truetype("LindenHill-webfont.ttf", 26) # Replace "arial.ttf" with your desired font file
|
||||
|
||||
|
|
@ -13,7 +22,7 @@ font = ImageFont.truetype("LindenHill-webfont.ttf", 26) # Replace "arial.ttf" w
|
|||
|
||||
quote_resp = requests.get("https://www.adafruit.com/api/quotes.php").json()
|
||||
|
||||
text = f"{quote_resp[0]["text"]} - {quote_resp[0]["author"]}"
|
||||
text = f'{quote_resp[0]["text"]} - {quote_resp[0]["author"]}'
|
||||
|
||||
#print(font.getbbox(text))
|
||||
x, y, text_width, text_height = font.getbbox(text)
|
||||
|
|
@ -23,16 +32,16 @@ draw = ImageDraw.Draw(full_txt_img)
|
|||
draw.text((3, 3), text, font=font, fill=(255, 0, 255))
|
||||
#img.save("quote.png")
|
||||
|
||||
single_frame_img = Image.new("RGB", (64, 32), (0, 0, 0))
|
||||
single_frame_img = Image.new("RGB", (width, height), (0, 0, 0))
|
||||
|
||||
geometry = adafruit_raspberry_pi5_piomatter.Geometry(width=64, height=64, n_addr_lines=4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.R180)
|
||||
geometry = adafruit_raspberry_pi5_piomatter.Geometry(width=width, height=height, n_addr_lines=4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.R180)
|
||||
framebuffer = np.asarray(single_frame_img) + 0 # Make a mutable copy
|
||||
|
||||
matrix = adafruit_raspberry_pi5_piomatter.AdafruitMatrixBonnetRGB888Packed(framebuffer, geometry)
|
||||
|
||||
|
||||
for x_pixel in text_width:
|
||||
single_frame_img = full_txt_img.crop(x_pixel, 0, 64, 32)
|
||||
single_frame_img.paste(full_txt_img.crop(x_pixel, 0, width, height))
|
||||
framebuffer[:] = np.asarray(single_frame_img)
|
||||
matrix.show()
|
||||
time.sleep(0.01)
|
||||
Loading…
Reference in a new issue