feat: Introduce visual effects module, enhance text rendering with SSAA, and add shifting gradient support.

This commit is contained in:
2026-03-14 22:15:48 -07:00
parent 1ff2e54586
commit 2e6b2c48bd
3 changed files with 147 additions and 7 deletions

View File

@@ -71,8 +71,11 @@ def render_line(text, fnt=None):
draw = ImageDraw.Draw(img)
draw.text((-bbox[0] + pad, -bbox[1] + pad), text, fill=255, font=fnt)
pix_h = config.RENDER_H * 2
scale = pix_h / max(img_h, 1)
new_w = max(1, int(img_w * scale))
hi_h = pix_h * config.SSAA
scale = hi_h / max(img_h, 1)
new_w_hi = max(1, int(img_w * scale))
img = img.resize((new_w_hi, hi_h), Image.Resampling.LANCZOS)
new_w = max(1, int(new_w_hi / config.SSAA))
img = img.resize((new_w, pix_h), Image.Resampling.LANCZOS)
data = img.tobytes()
thr = 80
@@ -129,8 +132,8 @@ def big_wrap(text, max_w, fnt=None):
return out
def lr_gradient(rows):
"""Color each non-space block character with a left-to-right gradient."""
def lr_gradient(rows, offset=0.0):
"""Color each non-space block character with a shifting left-to-right gradient."""
n = len(GRAD_COLS)
max_x = max((len(r.rstrip()) for r in rows if r.strip()), default=1)
out = []
@@ -143,7 +146,8 @@ def lr_gradient(rows):
if ch == ' ':
buf.append(' ')
else:
idx = min(round(x / max(max_x - 1, 1) * (n - 1)), n - 1)
shifted = (x / max(max_x - 1, 1) + offset) % 1.0
idx = min(round(shifted * (n - 1)), n - 1)
buf.append(f"{GRAD_COLS[idx]}{ch}\033[0m")
out.append("".join(buf))
return out
@@ -165,7 +169,6 @@ def make_block(title, src, ts, w):
("\u201d",'"'), ("\u2013","-"), ("\u2014","-")]:
title_up = title_up.replace(old, new)
big_rows = big_wrap(title_up, w - 4, lang_font)
big_rows = lr_gradient(big_rows)
hc = random.choice([
"\033[38;5;46m", # matrix green
"\033[38;5;34m", # dark green