Make the diplsay size configurable via LEDCAT_GEOMETRY

This commit is contained in:
polyfloyd 2017-09-25 22:36:07 +02:00
parent e3d92b0eee
commit 23178cb121
7 changed files with 15 additions and 10 deletions

View file

@ -2,14 +2,16 @@
from collections import namedtuple from collections import namedtuple
import math import math
import os
import os.path as path import os.path as path
import random import random
import sys import sys
import time import time
from PIL import Image # Requires the Pillow library from PIL import Image # Requires the Pillow library
DISP_WIDTH = 150 _geometry = os.getenv('LEDCAT_GEOMETRY', '150x16').split('x')
DISP_HEIGHT = 16 DISP_WIDTH = int(_geometry[0])
DISP_HEIGHT = int(_geometry[1])
tail_colors = [ tail_colors = [
@ -28,8 +30,7 @@ def read_image(filename):
anim_cat = [] anim_cat = []
for i in range(0, 6): for i in range(0, 6):
frame = read_image('%s/cat/%d.png' % (path.dirname(__file__), i)) frame = read_image('%s/cat/%d.png' % (path.dirname(__file__), i))
assert frame.size[0] == DISP_WIDTH assert (32, 16) == frame.size
assert frame.size[1] == DISP_HEIGHT
anim_cat.append(frame) anim_cat.append(frame)
anim_sparkle = [] anim_sparkle = []
for i in range(0, 5): for i in range(0, 5):
@ -57,17 +58,21 @@ while True:
i = y * DISP_WIDTH + x i = y * DISP_WIDTH + x
t = time.time() t = time.time()
col_y = y - (DISP_HEIGHT // 2 - len(tail_colors) // 2) + int(math.sin(x / 6 + t * math.pi) * 4 * math.sin(t * 8)) col_y = y - (DISP_HEIGHT // 2 - len(tail_colors) // 2) + int(math.sin(x / 6 + t * math.pi) * 4 * math.sin(t * 8))
if x < 130 and 0 <= col_y < len(tail_colors): if x < (DISP_WIDTH - 10) and 0 <= col_y < len(tail_colors):
color = tail_colors[col_y] color = tail_colors[col_y]
else: else:
color = (0x0f, 0x4d, 0x8f) color = (0x0f, 0x4d, 0x8f)
frame[i*3:i*3+3] = color frame[i*3:i*3+3] = color
# Paste animated frame # Copy animated frame
for i in range(DISP_WIDTH * DISP_HEIGHT): for anim_x in range(anim_frame.size[0]):
pix = anim_frame.getpixel((i % DISP_WIDTH, i / DISP_WIDTH)) for anim_y in range(anim_frame.size[1]):
if pix[3] != 0: pix = anim_frame.getpixel((anim_x, anim_y))
frame[i*3:i*3+3] = pix[:3] if pix[3] != 0: # Test for alpha
x = (DISP_WIDTH - anim_frame.size[0]) + anim_x
y = (DISP_HEIGHT // 2 - anim_frame.size[1] // 2) + anim_y
i = ((y * DISP_WIDTH) + x) * 3
frame[i:i+3] = pix[:3]
# Render and update the sparkles # Render and update the sparkles
for sp in sparkles: for sp in sparkles:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

After

Width:  |  Height:  |  Size: 341 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 430 B

After

Width:  |  Height:  |  Size: 346 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 B

After

Width:  |  Height:  |  Size: 346 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 346 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 B

After

Width:  |  Height:  |  Size: 342 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 435 B

After

Width:  |  Height:  |  Size: 351 B

Before After
Before After