Files
LihonT/scripts/make_serena_promo.py
cheb0chik 8b7fa5ff57 LihonT 2 Serena alpha
Themes as data: the settings and the rest of TikTok take a look (Stickers, Windows 95, or a theme a plugin brings with the
right ui.theme); the DEBUG recovery mode (Clear cache in Android resets the look and puts the plugins in safe mode); new
plugin functions (name.style, confetti and buzz on a tap); a few memory trims in the chat bubbles; the person list for bubbles
no longer shows screen labels.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 12:32:37 +03:00

365 lines
18 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
LihonT 2 «Serena alpha» promo in the sticker style of make_luna_promo2.py: 1080x1920, 30 fps, about 36 seconds.
Everything is drawn here (no screenshots): the settings card that changes theme, the Windows 95 windows, the plugin code that
types itself, the wave name, the confetti and the recovery mode. The look helpers come from make_luna_promo2.py.
usage (from the repository root):
py -X utf8 -B scripts/make_serena_promo.py # work/serena-promo/serena_promo.mp4
py -X utf8 -B scripts/make_serena_promo.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_promo.mp4"
AUDIO = ROOT / "work" / "serena-promo" / "serena_audio.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.6, CREAM),
("themes", 3.6, 9.6, (255, 226, 200)),
("win95", 9.6, 14.4, (0, 128, 128)),
("plugin", 14.4, 20.4, (255, 236, 150)),
("fun", 20.4, 25.6, (215, 200, 255)),
("debug", 25.6, 31.0, (190, 240, 220)),
("outro", 31.0, 35.4, (255, 196, 176)),
]
DURATION = SCENES[-1][2]
FRAMES = int(round(DURATION * FPS))
WIPE = V.WIPE
# the looks a settings card can have: (page, card, ink, radius, outline, shadow, bevel, tick box, title bars, accent, on accent)
LOOKS = {
"md3": dict(page=(254, 247, 255), card=(243, 237, 247), ink=(29, 27, 32), radius=34, outline=0, shadow=0, bevel=False,
tick=False, bars=False, accent=(103, 80, 164), on=(255, 255, 255), name="Material 3"),
"sticker": dict(page=(255, 244, 224), card=(255, 255, 255), ink=INK, radius=30, outline=6, shadow=10, bevel=False,
tick=False, bars=False, accent=VIOLET, on=WHITE, name="Стикеры"),
"win95": dict(page=(0, 128, 128), card=(192, 192, 192), ink=(0, 0, 0), radius=0, outline=0, shadow=0, bevel=True,
tick=True, bars=True, accent=(0, 0, 128), on=WHITE, name="Windows 95"),
"sunset": dict(page=(43, 29, 58), card=(61, 43, 82), ink=(251, 233, 255), radius=34, outline=5, shadow=8, bevel=False,
tick=False, bars=False, accent=(255, 138, 91), on=(43, 29, 58), name="Закат (плагин)"),
}
def bevel(d, box, raised=True, edge=3, face=(192, 192, 192)):
x0, y0, x1, y1 = [int(v) for v in box]
d.rectangle([x0, y0, x1, y1], fill=face + (255,))
light, mid, dark, black = (255, 255, 255), (223, 223, 223), (128, 128, 128), (0, 0, 0)
tl1, br1, tl2, br2 = (light, black, mid, dark) if raised else (dark, light, black, mid)
for k, (tl, br) in enumerate(((tl1, br1), (tl2, br2))):
o = k * edge
d.rectangle([x0 + o, y0 + o, x1 - o - edge, y0 + o + edge - 1], fill=tl + (255,))
d.rectangle([x0 + o, y0 + o, x0 + o + edge - 1, y1 - o - edge], fill=tl + (255,))
d.rectangle([x0 + o + edge, y1 - o - edge + 1, x1 - o, y1 - o], fill=br + (255,))
d.rectangle([x1 - o - edge + 1, y0 + o + edge, x1 - o, y1 - o], fill=br + (255,))
def settings_card(layer, look, box, lt=0.0, rows=None):
"""A mock of the mod's settings screen in a given look: a page, a title strip and four rows with switches."""
L = LOOKS[look] if isinstance(look, str) else look
x0, y0, x1, y1 = box
d = ImageDraw.Draw(layer, "RGBA")
d.rectangle([x0 - 30, y0 - 30, x1 + 30, y1 + 30], fill=L["page"] + (255,))
inner = (x0, y0 + 70, x1 - L["shadow"], y1 - L["shadow"])
if L["shadow"]:
d.rounded_rectangle([inner[0] + L["shadow"], inner[1] + L["shadow"], inner[2] + L["shadow"], inner[3] + L["shadow"]],
radius=L["radius"], fill=(0, 0, 0, 255) if look == "sunset" else INK + (255,))
if L["bevel"]:
bevel(d, inner, True)
else:
d.rounded_rectangle(inner, radius=L["radius"], fill=L["card"] + (255,),
outline=L["ink"] + (255,) if L["outline"] else None, width=L["outline"] or 0)
# section title
if L["bars"]:
for i in range(x1 - x0):
k = i / max(1, x1 - x0)
d.line([(x0 + i, y0 + 8), (x0 + i, y0 + 62)], fill=(int(0 + 16 * k), int(0 + 132 * k), int(128 + 80 * k), 255))
P.draw_text(layer, (x0 + 24, y0 + 35), "Функции", 36, L["on"] + (255,), anchor="lm")
else:
P.draw_text(layer, (x0 + 28, y0 + 35), "Функции", 38, (L["accent"] if look != "sticker" else L["ink"]) + (255,), anchor="lm")
names = rows or ["Призрак: истории", "Свои пузыри", "Несколько фото", "Автопродление"]
step = (inner[3] - inner[1]) / len(names)
for n, text in enumerate(names):
cy = inner[1] + step * (n + 0.5)
P.draw_text(layer, (x0 + 40, cy), text, 40, L["ink"] + (255,), anchor="lm")
on = clamp((lt - 0.2 - n * 0.25) / 0.3) if lt >= 0 else 1.0
cx = x1 - 90 - L["shadow"]
if L["tick"]:
bevel(d, (cx - 24, cy - 24, cx + 24, cy + 24), False, 3, (255, 255, 255))
if on > 0.5:
d.line([(cx - 13, cy), (cx - 4, cy + 11), (cx + 14, cy - 12)], fill=(0, 0, 0, 255), width=7)
else:
track = tuple(int(L["card"][i] * (1 - on) + L["accent"][i] * on) for i in range(3))
d.rounded_rectangle([cx - 56, cy - 30, cx + 56, cy + 30], radius=30, fill=track + (255,), outline=L["ink"] + (255,),
width=4 if L["outline"] else 2)
kx = cx - 26 + 52 * on
d.ellipse([kx - 20, cy - 20, kx + 20, cy + 20], fill=(L["on"] if on > 0.5 else L["ink"]) + (255,))
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=14)
V.title(layer, max(0.0, lt - 0.9), "LihonT 2", "Serena alpha", y=1230)
V.label(layer, W / 2, 1480, "темы · приколы · восстановление", pop(lt, 1.8), size=44, fill=YELLOW)
def scene_themes(layer, lt):
V.title(layer, lt, "Темы оформления", "Выбери вид, как хочешь")
order = ["md3", "sticker", "win95"]
idx = min(len(order) - 1, int(lt / 1.55))
part = (lt % 1.55) / 1.55
look = order[idx]
settings_card(layer, look, (150, 620, 930, 1240), lt=lt - idx * 1.55)
# the name of the look flies in on a sticker
V.label(layer, W / 2, 1400, LOOKS[look]["name"], pop(part, 0.0, 0.4), size=64, fill=YELLOW)
for n, key in enumerate(order):
V.label(layer, 220 + n * 320, 1560, LOOKS[key]["name"], pop(lt, 4.2 + n * 0.2), size=32,
fill=WHITE if key != look else MINT)
V.label(layer, W / 2, 1700, "И свои темы из плагинов", pop(lt, 4.8), size=40, fill=PINK)
if part < 0.08:
V.ring(layer, W / 2, 930, part, 0.0, color=INK, size=420)
def scene_win95(layer, lt):
d = ImageDraw.Draw(layer, "RGBA")
P.draw_text(layer, (W / 2, 190), "Windows 95 везде", 100, WHITE + (255,))
P.draw_text(layer, (W / 2, 290), "не только в настройках", 46, (230, 255, 255, 255), bold=False)
# a phone-ish screen: windows with navy title bars
px0, py0, px1, py1 = 170, 400, 910, 1700
d.rectangle([px0 - 14, py0 - 14, px1 + 14, py1 + 14], fill=(20, 20, 20, 255))
d.rectangle([px0, py0, px1, py1], fill=(0, 128, 128, 255))
for n, (title, lines) in enumerate((("Комментарии", ["anna: смотрите, вайб!", "luna: нашёл своих"]),
("Профиль", ["подписчики: 5 095", "лайки: 21,2 тыс."]))):
k = ease_out_back((lt - 0.3 - n * 0.4) / 0.5)
if k <= 0.02:
continue
y0 = py0 + 50 + n * 480 + (1 - k) * 300
bevel(d, (px0 + 40, y0, px1 - 40, y0 + 420), True, 4)
for i in range(px1 - px0 - 100):
kk = i / max(1, px1 - px0 - 100)
d.line([(px0 + 52 + i, y0 + 12), (px0 + 52 + i, y0 + 62)], fill=(int(16 * kk), int(132 * kk), int(128 + 80 * kk), 255))
P.draw_text(layer, (px0 + 70, y0 + 38), title, 36, WHITE + (255,), anchor="lm")
bevel(d, (px1 - 130, y0 + 16, px1 - 100, y0 + 58), True, 2)
for i, text in enumerate(lines):
bevel(d, (px0 + 66, y0 + 96 + i * 150, px1 - 66, y0 + 216 + i * 150), False, 3, (255, 255, 255))
P.draw_text(layer, (px0 + 90, y0 + 156 + i * 150), text, 34, (0, 0, 0, 255), anchor="lm")
# the bottom bar: square tabs, the chosen one pressed in
by = py1 - 170
bevel(d, (px0, by, px1, py1), True, 4)
for i in range(5):
x = px0 + 20 + i * 140
pressed = i == 1
bevel(d, (x, by + 22, x + 120, by + 130), not pressed, 3)
d.rectangle([x + 40, by + 52, x + 80, by + 92], outline=(0, 0, 0, 255), width=5)
V.label(layer, W / 2, 1810, "Панель, комментарии, профиль, меню", pop(lt, 1.8), size=36, fill=YELLOW)
TYPED = [
'plugin = Plugin("Закат", author="Вася")',
"plugin.theme(",
' page="#2b1d3a", card="#3d2b52",',
' text="#fbe9ff", accent="#ff8a5b",',
" radius=20, outline=2, shadow=4)",
"plugin.save()",
]
def scene_plugin(layer, lt):
V.title(layer, lt, "Тема из плагина", "Пять строк на Python")
d = ImageDraw.Draw(layer, "RGBA")
box = (90, 470, 990, 1010)
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([130 + i * 44, 505, 160 + i * 44, 535], fill=c + (255,))
total = sum(len(t) + 1 for t in TYPED)
shown = int(clamp((lt - 0.5) / 3.0) * total)
y = 580
for line in TYPED:
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, (130, y), part, 36, color, bold=False, anchor="lm")
y += 64
if shown < 0:
break
# the result appears as a card in the new theme
k = pop(lt, 3.8, 0.6)
if k > 0.02:
V.place(layer, _card_image("sunset", 780, 520), W / 2, 1380 + (1 - k) * 200, 0.85 * k)
V.label(layer, W / 2, 1720, "Защитник проверит контраст", pop(lt, 4.4), size=36, fill=WHITE)
_cache = {}
def _card_image(look, w, h):
key = (look, w, h)
if key not in _cache:
img = Image.new("RGBA", (w + 80, h + 80), (0, 0, 0, 0))
settings_card(img, look, (40, 40, 40 + w, 40 + h), lt=-1)
_cache[key] = img
return _cache[key]
def scene_fun(layer, lt):
V.title(layer, lt, "Приколы", "Имя, конфетти, вибрация")
d = ImageDraw.Draw(layer, "RGBA")
# a name that turns into a wave, letter by letter
word = "Привет, мир"
f = P.font(110)
total = d.textlength(word, font=f)
x = W / 2 - total / 2
done = int(clamp((lt - 0.6) / 1.4) * len(word))
for n, ch in enumerate(word):
shown = ch.upper() if (n % 2 == 1 and n < done) else ch.lower()
w = d.textlength(ch, font=f)
bob = math.sin(lt * 5 + n * 0.7) * 10 if n < done else 0
P.draw_text(layer, (x + w / 2, 700 + bob), shown, 110, INK + (255,))
x += w
V.label(layer, W / 2, 840, "name.style: wave", pop(lt, 1.0), size=40, fill=YELLOW)
# a star sticker that is tapped and throws confetti
cx, cy = W / 2, 1230
k = pop(lt, 2.4)
pts = []
for i in range(10):
r = 130 if i % 2 == 0 else 58
a = -math.pi / 2 + i * math.pi / 5
pts.append((cx + math.cos(a) * r * k, cy + math.sin(a) * r * k))
if k > 0.02:
d.polygon([(x + 8, y + 8) for x, y in pts], fill=INK + (255,))
d.polygon(pts, fill=YELLOW + (255,), outline=INK + (255,))
d.line(pts + [pts[0]], fill=INK + (255,), width=6)
tap = 3.4
if lt > tap:
V.burst(layer, cx, cy, lt, tap, seed=3, count=60, power=1100)
V.ring(layer, cx, cy, lt, tap, color=INK, size=260)
for i in range(3): # little buzz marks beside the star
off = 170 + i * 26
a = int(255 * clamp(1 - (lt - tap) / 0.8))
d.arc([cx - off, cy - off, cx + off, cy + off], 150, 210, fill=INK + (a,), width=6)
d.arc([cx - off, cy - off, cx + off, cy + off], -30, 30, fill=INK + (a,), width=6)
V.label(layer, W / 2, 1480, "tap: confetti + buzz", pop(lt, 2.8), size=40, fill=PINK)
V.label(layer, W / 2, 1620, "Всё безопасно: только у вас на экране", pop(lt, 3.6), size=34, fill=WHITE)
def scene_debug(layer, lt):
V.title(layer, lt, "Режим DEBUG", "Если тема всё сломала")
d = ImageDraw.Draw(layer, "RGBA")
# the switch
V.sticker(layer, (110, 480, 970, 640), WHITE, radius=44)
P.draw_text(layer, (160, 560), "Режим DEBUG", 48, INK + (255,), anchor="lm")
V.switch(layer, 850, 560, ease_out_cubic((lt - 0.6) / 0.4))
# Android: Clear cache
pressed = clamp((lt - 2.2) / 0.3)
V.sticker(layer, (110, 740, 970, 900), (230, 230, 240), radius=44, shadow=int(10 * (1 - pressed)))
P.draw_text(layer, (160, 820), "Android → TikTok → Очистить кэш", 38, INK + (255,), anchor="lm")
d.ellipse([850 - 36, 820 - 36, 850 + 36, 820 + 36], fill=CORAL + (255,), outline=INK + (255,), width=5)
# the card: Windows 95 for a moment, then back to Material 3 with a burst
back = lt > 3.0
look = "md3" if back else "win95"
if lt > 1.0:
settings_card(layer, look, (150, 1030, 930, 1560), lt=-1)
if back:
V.burst(layer, W / 2, 1300, lt, 3.0, seed=9, count=50, power=900)
V.ring(layer, W / 2, 1300, lt, 3.0, color=INK, size=380)
V.label(layer, W / 2, 1690, "Оформление и плагины сброшены", pop(lt, 3.3), size=38, fill=YELLOW)
V.label(layer, W / 2, 1790, "Файлы плагинов остаются", pop(lt, 3.8), size=34, fill=WHITE)
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=19, count=60, power=1000)
V.title(layer, max(0.0, lt - 0.5), "Serena alpha", "Открытый код · лицензия 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)
if name != "win95":
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 / ("still_%.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()