Files
LihonT/scripts/make_serena_promo2.py
cheb0chik 38e7b2551e LihonT 2 Serena alpha 2
Plugin icons for the feed buttons (right ui.icons: like, comment, collect, share), preview cards that a theme author
attaches and the list of looks shows before a theme is picked, the sample plugins lihont.icons-sticker, lihont.theme-win95 and
lihont.theme-sunset with their pictures, docs, SDK, skill and tests for all of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 13:08:56 +03:00

277 lines
14 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
LihonT 2 «Serena alpha 2» promo in the sticker style: 1080x1920, 30 fps, about 29 seconds.
New in it: the plugin icons for the feed buttons (white TikTok icons turn into sticker ones), the preview cards an author attaches
to a theme and the list of looks that shows them, the five lines that bring both, and what plugins can never get.
Everything is drawn here; the sticker icons and the preview cards are the real pictures of the sample plugins.
usage (from the repository root):
py -X utf8 -B scripts/make_serena_promo2.py # work/serena-promo/serena_promo2.mp4
py -X utf8 -B scripts/make_serena_promo2.py --still 9.0 # one frame
"""
from __future__ import annotations
import argparse
import math
import shutil
import subprocess
import sys
from multiprocessing import Pool
from pathlib import Path
from PIL import Image, ImageDraw
sys.path.insert(0, str(Path(__file__).resolve().parent))
import make_luna_promo2 as V # noqa: E402
import make_lihont_promo as P # noqa: E402
W, H, FPS = V.W, V.H, V.FPS
ROOT = V.ROOT
OUT = ROOT / "work" / "serena-promo" / "serena_promo2.mp4"
AUDIO = ROOT / "work" / "serena-promo" / "serena_audio2.wav"
INK, CREAM, CORAL, YELLOW, MINT, VIOLET, SKY, PINK, WHITE = V.INK, V.CREAM, V.CORAL, V.YELLOW, V.MINT, V.VIOLET, V.SKY, V.PINK, V.WHITE
clamp, ease_out_cubic, ease_out_back, pop = V.clamp, V.ease_out_cubic, V.ease_out_back, V.pop
SCENES = [
("intro", 0.0, 3.2, CREAM),
("icons", 3.2, 9.4, (190, 240, 220)),
("cards", 9.4, 15.6, (215, 200, 255)),
("author", 15.6, 21.0, (255, 236, 150)),
("safe", 21.0, 25.4, (255, 205, 225)),
("outro", 25.4, 29.6, (255, 196, 176)),
]
DURATION = SCENES[-1][2]
FRAMES = int(round(DURATION * FPS))
WIPE = V.WIPE
ICONS = ROOT / "plugins" / "lihont.icons-sticker" / "assets"
CARDS = ROOT / "plugins" / "lihont.theme-sunset" / "assets"
_extra: dict = {}
def extra():
if not _extra:
_extra["icons"] = {n: Image.open(ICONS / (n + ".png")).convert("RGBA").resize((150, 150), Image.Resampling.LANCZOS)
for n in ("heart", "bubble", "star", "plane")}
_extra["cards"] = [Image.open(CARDS / ("preview%d.png" % n)).convert("RGBA") for n in (1, 2)]
return _extra
def tiktok_icon(layer, kind, cx, cy):
"""The plain white icons of TikTok's feed: a heart, a bubble with dots, a bookmark and an arrow."""
d = ImageDraw.Draw(layer, "RGBA")
w = (255, 255, 255, 255)
if kind == "heart":
d.ellipse([cx - 62, cy - 52, cx, cy + 10], fill=w)
d.ellipse([cx, cy - 52, cx + 62, cy + 10], fill=w)
d.polygon([(cx - 60, cy - 14), (cx + 60, cy - 14), (cx, cy + 62)], fill=w)
elif kind == "bubble":
d.rounded_rectangle([cx - 62, cy - 50, cx + 62, cy + 34], radius=40, fill=w)
d.polygon([(cx - 30, cy + 30), (cx - 44, cy + 62), (cx + 6, cy + 32)], fill=w)
for dx in (-30, 0, 30):
d.ellipse([cx + dx - 8, cy - 18, cx + dx + 8, cy - 2], fill=(150, 150, 160, 255))
elif kind == "star":
d.polygon([(cx - 44, cy - 62), (cx + 44, cy - 62), (cx + 44, cy + 62), (cx, cy + 28), (cx - 44, cy + 62)], fill=w)
else:
d.polygon([(cx - 66, cy + 6), (cx + 8, cy - 58), (cx + 8, cy - 22), (cx + 66, cy - 22), (cx + 66, cy + 40),
(cx + 8, cy + 40), (cx + 8, cy + 62)], fill=w)
def scene_intro(layer, lt):
k = ease_out_back(lt / 0.9)
V.place(layer, V.ASSETS["logo"], W / 2, 760, 0.5 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 360)
V.burst(layer, W / 2, 760, lt, 0.6, seed=24)
V.title(layer, max(0.0, lt - 0.9), "Serena alpha 2", "значки и карточки тем", y=1230)
V.label(layer, W / 2, 1480, "плагины умеют больше", pop(lt, 1.8), size=44, fill=YELLOW)
def scene_icons(layer, lt):
V.title(layer, lt, "Свои значки", "кнопки ленты, как вам хочется")
d = ImageDraw.Draw(layer, "RGBA")
# a feed screen: dark panel with the four buttons on the right
box = (150, 480, 930, 1540)
d.rounded_rectangle([box[0] + 10, box[1] + 10, box[2] + 10, box[3] + 10], radius=48, fill=INK + (255,))
d.rounded_rectangle(box, radius=48, fill=(46, 34, 66, 255), outline=INK + (255,), width=6)
for i in range(0, 760, 40):
d.line([(box[0] + 6, box[1] + 20 + i * 1.3), (box[2] - 6, box[1] + 90 + i * 1.3)], fill=(60, 44, 84, 255), width=3)
P.draw_text(layer, (230, 1470), "@автор #видео", 36, (255, 255, 255, 220), bold=False, anchor="lm")
names = ("heart", "bubble", "star", "plane")
counts = ("26,9 тыс.", "574", "5099", "8616")
for n, name in enumerate(names):
cx, cy = 810, 640 + n * 215
swapped = lt > 2.0 + n * 0.45
if swapped:
k = clamp(pop(lt, 2.0 + n * 0.45, 0.5), 0, 1.15)
V.place(layer, extra()["icons"][name], cx, cy, k)
V.ring(layer, cx, cy, lt, 2.0 + n * 0.45, color=MINT, size=110)
else:
tiktok_icon(layer, name, cx, cy)
P.draw_text(layer, (cx, cy + 92), counts[n], 30, (255, 255, 255, 255), anchor="mm")
V.burst(layer, 810, 860, lt, 2.0, seed=7, count=36, power=800)
V.label(layer, W / 2, 1640, "plugin.icons(like=\"heart.png\", ...)", pop(lt, 0.8), size=34, fill=WHITE)
V.label(layer, W / 2, 1760, "Кнопки на местах и работают как раньше", pop(lt, 3.6), size=34, fill=YELLOW)
def scene_cards(layer, lt):
V.title(layer, lt, "Карточки тем", "автор показывает, как выглядит")
d = ImageDraw.Draw(layer, "RGBA")
x0, x1, y0 = 90, 990, 470
V.sticker(layer, (x0, y0, x1, 1560), WHITE, radius=44)
P.draw_text(layer, (x0 + 50, y0 + 60), "Оформление", 46, INK + (255,), anchor="lm")
rows = [("Material 3", "Мягкие скругления"), ("Windows 95", "Серые окна, объёмные кнопки"),
("Закат (плагин)", "Тема из плагина, автор Вася")]
y = y0 + 130
for n, (name, hint) in enumerate(rows):
chosen = n == 2 and lt > 1.6
h = 150 if n < 2 else (540 if chosen else 150)
fill = (255, 236, 150) if chosen else (255, 255, 255)
d.rounded_rectangle([x0 + 30, y, x1 - 30, y + h], radius=30, fill=fill + (255,), outline=INK + (255,), width=4)
P.draw_text(layer, (x0 + 70, y + 40), name + (" ✓" if chosen and lt > 3.6 else ""), 42, INK + (255,), anchor="lm")
P.draw_text(layer, (x0 + 70, y + 98), hint, 30, (90, 80, 110, 255), bold=False, anchor="lm")
if chosen:
# the author's cards slide in from the right, one after the other, and the row scrolls sideways
slide = ease_out_cubic((lt - 2.0) / 0.9)
shift = -math.sin(clamp((lt - 3.4) / 1.6) * math.pi) * 36
for i, card in enumerate(extra()["cards"]):
cw, ch = 360, 270
c = card.resize((cw, ch), Image.Resampling.LANCZOS)
cx = x0 + 70 + i * (cw + 24) + (1 - slide) * 700 + shift
if cx + cw < x1 - 40 or cx < x1 - 100:
layer.alpha_composite(c, (int(cx), int(y + 170)))
d.rounded_rectangle([cx, y + 170, cx + cw, y + 170 + ch], radius=10, outline=INK + (255,), width=4)
V.ring(layer, x1 - 120, y + 60, lt, 1.6, color=INK, size=120)
y += h + 24
V.label(layer, W / 2, 1650, "Карточки кладёт сам автор", pop(lt, 0.9), size=38, fill=PINK)
V.label(layer, W / 2, 1760, "Видно ещё до выбора", pop(lt, 1.4), size=36, fill=WHITE)
CODE = [
'plugin = Plugin("Закат", author="Вася")',
"plugin.theme(",
' page="#2b1d3a", card="#3d2b52",',
' text="#fbe9ff", accent="#ff8a5b",',
' preview=["card1.png", "card2.png"])',
'plugin.icons(like="heart.png")',
"plugin.save()",
]
def scene_author(layer, lt):
V.title(layer, lt, "Как это сделать", "один файл на Python")
d = ImageDraw.Draw(layer, "RGBA")
box = (80, 470, 1000, 1110)
d.rounded_rectangle([box[0] + 10, box[1] + 10, box[2] + 10, box[3] + 10], radius=36, fill=INK + (255,))
d.rounded_rectangle(box, radius=36, fill=(34, 28, 46, 255), outline=INK + (255,), width=6)
for i, c in enumerate((CORAL, YELLOW, MINT)):
d.ellipse([120 + i * 44, 505, 150 + i * 44, 535], fill=c + (255,))
total = sum(len(t) + 1 for t in CODE)
shown = int(clamp((lt - 0.5) / 3.0) * total)
y = 590
for line in CODE:
part = line[:max(0, shown)]
shown -= len(line) + 1
color = (255, 205, 60, 255) if line.startswith("plugin.") else (251, 233, 255, 255)
P.draw_text(layer, (120, y), part, 36, color, bold=False, anchor="lm")
y += 66
if shown < 0:
break
V.label(layer, 330, 1240, "ui.theme", pop(lt, 3.6), size=48, fill=SKY)
V.label(layer, 720, 1240, "ui.icons", pop(lt, 3.9), size=48, fill=MINT)
V.label(layer, W / 2, 1400, "Права видно в окне установки", pop(lt, 4.2), size=36, fill=WHITE)
V.label(layer, W / 2, 1520, "Защитник проверяет контраст", pop(lt, 4.5), size=36, fill=YELLOW)
def scene_safe(layer, lt):
V.title(layer, lt, "Безопасно", "плагины закрыты от этого навсегда")
items = [("пароли и коды входа", CORAL), ("токены и ключи", PINK), ("куки и сессии", YELLOW), ("тексты чатов", SKY),
("запуск кода", MINT)]
for n, (text, color) in enumerate(items):
k = ease_out_back((lt - 0.4 - n * 0.3) / 0.5)
x_off = (1 - k) * (900 if n % 2 else -900)
y = 600 + n * 190
V.sticker(layer, (110 + x_off, y - 70, 970 + x_off, y + 70), WHITE, radius=44)
d = ImageDraw.Draw(layer, "RGBA")
d.ellipse([150 + x_off, y - 34, 218 + x_off, y + 34], fill=color + (255,), outline=INK + (255,), width=5)
d.line([(166 + x_off, y - 16), (202 + x_off, y + 16)], fill=INK + (255,), width=7)
d.line([(202 + x_off, y - 16), (166 + x_off, y + 16)], fill=INK + (255,), width=7)
P.draw_text(layer, (250 + x_off, y), text, 44, INK + (255,), anchor="lm")
V.label(layer, W / 2, 1620, "Тема и значки только красят", pop(lt, 2.4), size=38, fill=YELLOW)
def scene_outro(layer, lt):
k = ease_out_back(lt / 0.8)
V.place(layer, V.ASSETS["logo"], W / 2, 620, 0.46 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 300)
V.burst(layer, W / 2, 620, lt, 0.5, seed=29, count=60, power=1000)
V.title(layer, max(0.0, lt - 0.5), "Serena alpha 2", "Открытый код · лицензия VCBFU v2", y=1000)
bounce = lambda t0: abs(math.sin((lt - t0) * 3)) * 14 if lt > t0 else 0 # noqa: E731
V.label(layer, W / 2, 1290 - bounce(1.2), "git.lihont.space", pop(lt, 1.2), size=60, fill=YELLOW)
V.label(layer, W / 2, 1440 - bounce(1.5), "Telegram · @lihont", pop(lt, 1.5), size=60, fill=WHITE)
V.label(layer, W / 2, 1580, "Это альфа: может быть шероховато", pop(lt, 2.2), size=34, fill=PINK)
SCENE_DRAW = {name: globals()["scene_" + name] for name, _, _, _ in SCENES}
def frame_at(t: float) -> Image.Image:
V.init_assets()
index = 0
for n, (name, start, end, color) in enumerate(SCENES):
if t >= start:
index = n
name, start, end, color = SCENES[index]
img = Image.new("RGBA", (W, H), color + (255,))
if index > 0 and t - start < WIPE:
prev = SCENES[index - 1][3]
img = Image.new("RGBA", (W, H), prev + (255,))
r = 1700 * ease_out_cubic((t - start) / WIPE)
mask = Image.new("L", (W, H), 0)
ImageDraw.Draw(mask).ellipse([W / 2 - r, H / 2 - r, W / 2 + r, H / 2 + r], fill=255)
img.paste(Image.new("RGBA", (W, H), color + (255,)), (0, 0), mask)
ox, oy = int(t * 30) % 80, int(t * 18) % 80
img.alpha_composite(V.ASSETS["dots"], (-ox, -oy))
layer = Image.new("RGBA", (W, H), (0, 0, 0, 0))
SCENE_DRAW[name](layer, t - start)
out = clamp((end - t) / 0.25) if index < len(SCENES) - 1 else 1.0
if out < 1.0:
layer.putalpha(layer.getchannel("A").point(lambda v, a=out: int(v * a)))
img.alpha_composite(layer)
return img
def render_frame(index: int) -> bytes:
return frame_at(index / FPS).convert("RGB").tobytes()
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--still", type=float)
parser.add_argument("--out", default=str(OUT))
parser.add_argument("--jobs", type=int, default=6)
args = parser.parse_args()
OUT.parent.mkdir(parents=True, exist_ok=True)
if args.still is not None:
path = OUT.parent / ("still2_%.2f.png" % args.still)
frame_at(args.still).convert("RGB").save(path)
print(path)
return
import make_lihont_music
make_lihont_music.generate(AUDIO, DURATION, tuple(s[1] for s in SCENES[1:]))
command = [shutil.which("ffmpeg") or "ffmpeg", "-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24",
"-s", "%dx%d" % (W, H), "-r", str(FPS), "-i", "-", "-i", str(AUDIO), "-c:v", "libx264", "-preset", "medium",
"-crf", "18", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "160k", "-shortest", args.out]
proc = subprocess.Popen(command, stdin=subprocess.PIPE)
with Pool(args.jobs, initializer=V.init_assets) as pool:
for n, data in enumerate(pool.imap(render_frame, range(FRAMES), chunksize=4)):
proc.stdin.write(data)
if n % 60 == 0:
print("frame %d/%d" % (n, FRAMES), flush=True)
proc.stdin.close()
proc.wait()
print("done:", args.out)
if __name__ == "__main__":
main()