Files
LihonT/scripts/make_luna_promo.py
cheb0chik 1d5a9a1fad LihonT 2 Luna
Ghost mode for stories and chats, several photos in one comment, .ltp plugins (rights, defender, rollback, downloads
only with consent), custom chat bubbles with a text colour of your choice, the lihont-ltp SDK and the plugin docs,
streak flames as widgets with a keeper, avatar shapes, Material 3 surfaces.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 18:19:27 +03:00

378 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 «Luna» promo video: 1080x1920, 30 fps, about 44 seconds, with the synthesised soundtrack of make_lihont_music.py.
Nothing in it is a screenshot: every scene is drawn here with Pillow (the bubbles, the settings rows, the ghost, the
plugin card, the avatar shapes) and the streak flames come from make_widget_preview.py, the same drawing the widget
shows on the phone. The earlier pre-release promo (make_lihont_promo.py) is only imported for its helpers and is not
changed.
usage (from the repository root):
py -X utf8 -B scripts/make_luna_promo.py # renders work/luna-promo/luna_promo.mp4
py -X utf8 -B scripts/make_luna_promo.py --still 14.0 # one frame at 14 s as work/luna-promo/still_14.00.png
"""
from __future__ import annotations
import argparse
import math
import random
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_lihont_promo as P # noqa: E402 (helpers only: fonts, easing, chips, shapes)
import make_widget_preview as WP # noqa: E402
W, H, FPS = P.W, P.H, P.FPS
ROOT = P.ROOT
OUT = ROOT / "work" / "luna-promo" / "luna_promo.mp4"
AUDIO = ROOT / "work" / "luna-promo" / "luna_audio.wav"
LOGO = P.LOGO
SCENES = [
("intro", 0.0, 3.4),
("flame", 3.4, 8.2),
("keeper", 8.2, 12.6),
("bubbles", 12.6, 17.8),
("ghost", 17.8, 22.2),
("photos", 22.2, 26.2),
("plugins", 26.2, 31.2),
("shapes", 31.2, 35.2),
("settings", 35.2, 39.6),
("outro", 39.6, 43.8),
]
DURATION = SCENES[-1][2]
FRAMES = int(round(DURATION * FPS))
FADE = P.FADE
BG, PRIMARY, ON, MUTED, CHIP, PINK, CORAL = P.BG, P.PRIMARY, P.ON, P.MUTED, P.CHIP, P.PINK, P.CORAL
SURFACE = (43, 39, 52)
clamp, ease_out_cubic, ease_out_back, pop = P.clamp, P.ease_out_cubic, P.ease_out_back, P.pop
draw_text, chip, headline, place = P.draw_text, P.chip, P.headline, P.place
ASSETS: dict = {}
# ---------------------------------------------------------------- small drawings
def gradient(w: int, h: int, c1, c2, vertical: bool = False) -> Image.Image:
img = Image.new("RGB", (w, h))
d = ImageDraw.Draw(img)
span = h if vertical else w
for i in range(span):
k = i / max(1, span - 1)
color = tuple(int(c1[n] + (c2[n] - c1[n]) * k) for n in range(3))
d.line([(0, i), (w, i)] if vertical else [(i, 0), (i, h)], fill=color)
return img
def rounded_mask(w: int, h: int, radius: int) -> Image.Image:
mask = Image.new("L", (w * 2, h * 2), 0)
ImageDraw.Draw(mask).rounded_rectangle([0, 0, w * 2 - 1, h * 2 - 1], radius=radius * 2, fill=255)
return mask.resize((w, h), Image.Resampling.LANCZOS)
def pictured(w: int, h: int, c1, c2, radius: int = 44, motif: tuple = (255, 255, 255, 70)) -> Image.Image:
"""A bubble with a picture of its own: a gradient with a flower pattern, like a photo a person would pick."""
img = gradient(w, h, c1, c2).convert("RGBA")
flower = P.flower(90, motif)
for x in range(-20, w, 130):
for y in range(-20 + (x // 130 % 2) * 60, h, 120):
img.alpha_composite(flower, (x, y)) if 0 <= x < w - 90 and 0 <= y < h - 90 else None
img.putalpha(rounded_mask(w, h, radius))
return img
def card(layer: Image.Image, box, fill=SURFACE, radius: int = 48, alpha: int = 255) -> None:
ImageDraw.Draw(layer, "RGBA").rounded_rectangle(box, radius=radius, fill=fill + (alpha,))
def switch(layer: Image.Image, cx: float, cy: float, on: float) -> None:
"""A Material 3 switch; on runs 0..1."""
d = ImageDraw.Draw(layer, "RGBA")
track = tuple(int(CHIP[n] + (PRIMARY[n] - CHIP[n]) * on) for n in range(3))
d.rounded_rectangle([cx - 62, cy - 36, cx + 62, cy + 36], radius=36, fill=track + (255,))
r = 22 + 8 * on
kx = cx - 26 + 52 * on
d.ellipse([kx - r, cy - r, kx + r, cy + r], fill=(BG if on > 0.5 else (150, 144, 160)) + (255,))
def ghost(size: int, bob: float) -> Image.Image:
s = size * 3
layer = Image.new("RGBA", (s, s), (0, 0, 0, 0))
d = ImageDraw.Draw(layer)
white = (240, 236, 248, 255)
d.ellipse([s * 0.2, s * 0.1, s * 0.8, s * 0.7], fill=white)
d.rectangle([s * 0.2, s * 0.4, s * 0.8, s * 0.82], fill=white)
for k in range(4):
cx = s * (0.275 + k * 0.15)
d.ellipse([cx - s * 0.075, s * 0.74, cx + s * 0.075, s * 0.9 + math.sin(bob * 3 + k) * s * 0.02], fill=white)
for ex in (0.38, 0.62):
d.ellipse([s * ex - s * 0.04, s * 0.36, s * ex + s * 0.04, s * 0.46], fill=(40, 34, 56, 255))
d.ellipse([s * 0.46, s * 0.5, s * 0.54, s * 0.58], fill=(40, 34, 56, 255))
return layer.resize((size, size), Image.Resampling.LANCZOS)
def init_assets() -> None:
if ASSETS:
return
ASSETS["bg"] = Image.new("RGBA", (W, H), BG + (255,))
ASSETS["blobs"] = [P.blob(360, (208, 188, 255, 62)), P.blob(300, (239, 184, 200, 52)), P.blob(260, (120, 200, 190, 36))]
ASSETS["flower"] = P.flower(70, (255, 255, 255, 26))
rnd = random.Random(3)
ASSETS["motes"] = [(rnd.random() * W, rnd.random() * H, 0.4 + rnd.random() * 0.9, rnd.random() * 6.28) for _ in range(16)]
ASSETS["logo"] = Image.open(LOGO).convert("RGBA")
ASSETS["flame_lit"] = [WP.render(True, n) for n in range(4)]
ASSETS["flame_grey"] = WP.render(False)
ASSETS["incoming"] = pictured(560, 150, (62, 60, 190), (28, 20, 110))
ASSETS["incoming_long"] = pictured(640, 150, (62, 60, 190), (28, 20, 110))
ASSETS["light"] = pictured(560, 150, (255, 226, 176), (255, 190, 200), motif=(255, 255, 255, 120))
ASSETS["mine"] = pictured(520, 150, (150, 60, 190), (90, 30, 140))
# ---------------------------------------------------------------- scenes
def scene_intro(layer, lt):
k = ease_out_back(lt / 0.9)
place(layer, ASSETS["blobs"][0], W / 2, 800, 1.2 * k)
place(layer, ASSETS["logo"], W / 2, 800, 0.46 * k * (1 + 0.03 * math.sin(lt * 4)), math.sin(lt * 2) * 3)
a = ease_out_cubic((lt - 0.5) / 0.5)
draw_text(layer, (W / 2, 1230 + (1 - a) * 40), "LihonT 2", 130, ON + (int(255 * a),))
b = ease_out_cubic((lt - 0.8) / 0.5)
draw_text(layer, (W / 2, 1360 + (1 - b) * 30), "Luna", 90, PRIMARY + (int(255 * b),))
c = ease_out_cubic((lt - 1.5) / 0.5)
draw_text(layer, (W / 2, 1500), "Что нового в релизе", 48, MUTED + (int(255 * c),), bold=False)
def scene_flame(layer, lt):
headline(layer, lt, "Живой огонёк", "Виджет серии, от 1×1 до 4×4")
rise = ease_out_cubic((lt - 0.2) / 0.8)
phase = int(lt / 0.22) % 4
lit = ASSETS["flame_lit"][phase]
place(layer, lit, 330, 960 + (1 - rise) * 700, 0.95)
place(layer, ASSETS["flame_grey"], 790, 800 + (1 - rise) * 700, 0.52)
place(layer, lit, 790, 1130 + (1 - rise) * 700, 0.34)
place(layer, lit, 610, 1130 + (1 - rise) * 700, 0.26)
chip(layer, 330, 1360, "Горит: оранжевый", pop(lt, 0.9), size=38)
chip(layer, 790, 1330, "Пора писать: серый", pop(lt, 1.3), size=34)
chip(layer, W / 2, 1560, "1×1 · 2×2 · 3×3 · 4×4", pop(lt, 1.8), size=40)
def scene_keeper(layer, lt):
headline(layer, lt, "Автопродление", "Огонёк сам, в нужное время")
k = ease_out_cubic((lt - 0.2) / 0.6)
card(layer, (110, 520 + (1 - k) * 300, 970, 1420 + (1 - k) * 300), radius=56)
names = ["Мама", "Друг", "Класс", "Сестра"]
t_flip = 2.0
for n, name in enumerate(names):
y = 640 + n * 190 + (1 - k) * 300
P.ImageDraw.Draw(layer, "RGBA").ellipse([160, y - 55, 270, y + 55], fill=(110 + n * 25, 90, 190 - n * 20, 255))
draw_text(layer, (310, y - 18), name, 46, ON + (255,), anchor="lm")
ImageDraw.Draw(layer, "RGBA").rounded_rectangle([310, y + 18, 310 + 260 - n * 30, y + 38], radius=10, fill=CHIP + (255,))
flipped = lt > t_flip + n * 0.35
flame = ASSETS["flame_lit"][int(lt / 0.2 + n) % 4] if flipped else ASSETS["flame_grey"]
place(layer, flame, 840, y, 0.2 * (1 + (0.25 * max(0.0, 1 - (lt - t_flip - n * 0.35) * 4) if flipped else 0)))
chip(layer, W / 2, 1530, "12:00", pop(lt, 0.8), size=70, fill=PRIMARY, fg=BG)
chip(layer, W / 2, 1660, "Сам пишет огонёк или ваш текст", pop(lt, 1.3), size=34)
def scene_bubbles(layer, lt):
headline(layer, lt, "Свои пузыри", "Любая картинка вместо фона")
items = [
(ASSETS["incoming"], 120, 560, "Привет! Это моя картинка", (255, 255, 255), 0.6),
(ASSETS["mine"], 440, 760, "Видно всё", (255, 255, 255), 1.1),
(ASSETS["light"], 120, 960, "На светлой чёрный", (35, 30, 45), 1.6),
(ASSETS["incoming_long"], 120, 1160, "На тёмной белый, сам", (255, 255, 255), 2.1),
]
for img, x, y, text, ink, t0 in items:
k = pop(lt, t0, 0.5)
if k <= 0.02:
continue
scaled = img.resize((max(1, int(img.width * k)), max(1, int(img.height * k))), Image.Resampling.BILINEAR)
cx = x + img.width / 2
layer.alpha_composite(scaled, (int(cx - scaled.width / 2), int(y + 75 - scaled.height / 2)))
if k > 0.7:
draw_text(layer, (x + 46, y + 75), text, 46, ink + (255,), anchor="lm")
chip(layer, 270, 1420, "Для каждого человека", pop(lt, 2.8), size=36)
chip(layer, 790, 1500, "Общая для незнакомцев", pop(lt, 3.2), size=36)
chip(layer, 540, 1640, "Картинки только на телефоне", pop(lt, 3.6), size=34, fill=PRIMARY, fg=BG)
def scene_ghost(layer, lt):
headline(layer, lt, "Режим призрака", "Смотрите и читайте незаметно")
bob = math.sin(lt * 2.2) * 18
place(layer, ASSETS["blobs"][1], W / 2, 760, 1.0)
place(layer, ghost(380, lt), W / 2, 760 + bob, ease_out_back(lt / 0.8))
card(layer, (110, 1070, 970, 1290), radius=48)
draw_text(layer, (170, 1135), "Истории", 50, ON + (255,), anchor="lm")
draw_text(layer, (170, 1215), "Автор не увидит вас в зрителях", 34, MUTED + (255,), bold=False, anchor="lm")
card(layer, (110, 1330, 970, 1550), radius=48)
draw_text(layer, (170, 1395), "Чаты", 50, ON + (255,), anchor="lm")
draw_text(layer, (170, 1475), "«Прочитано» не отправляется", 34, MUTED + (255,), bold=False, anchor="lm")
for y, t0 in ((1180, 1.2), (1440, 1.8)):
switch(layer, 850, y, ease_out_cubic((lt - t0) / 0.4))
chip(layer, W / 2, 1690, "Включается в «Приватность»", pop(lt, 2.4), size=36)
def scene_photos(layer, lt):
headline(layer, lt, "До 9 фото", "в одном комментарии")
colors = [((255, 160, 120), (220, 90, 140)), ((120, 200, 255), (70, 90, 200)), ((180, 255, 170), (60, 160, 130))]
for n in range(9):
k = pop(lt, 0.5 + n * 0.16, 0.5)
if k <= 0.02:
continue
row, col = divmod(n, 3)
c1, c2 = colors[(row + col) % 3]
tile = pictured(250, 250, c1, c2, radius=40, motif=(255, 255, 255, 90))
place(layer, tile, 240 + col * 300, 640 + row * 300, k)
card(layer, (90, 1620, 990, 1760), radius=70)
draw_text(layer, (160, 1690), "Написать комментарий…", 40, MUTED + (255,), bold=False, anchor="lm")
count = min(9, int(max(0.0, lt - 0.5) / 0.16) + 1)
chip(layer, 870, 1690, "%d/9" % count, 1.0, size=36, fill=PRIMARY, fg=BG)
def scene_plugins(layer, lt):
headline(layer, lt, "Плагины .ltp", "Свои дополнения без кода")
k = ease_out_back((lt - 0.2) / 0.8)
place(layer, ASSETS["blobs"][0], W / 2, 860, 1.1)
d = ImageDraw.Draw(layer, "RGBA")
s = 1.0 * k
x0, y0, x1, y1 = W / 2 - 190 * s, 860 - 250 * s, W / 2 + 190 * s, 860 + 250 * s
d.rounded_rectangle([x0, y0, x1, y1], radius=int(54 * s), fill=SURFACE + (255,), outline=PRIMARY + (255,), width=6)
draw_text(layer, (W / 2, 830), ".ltp", int(120 * s) + 1, PRIMARY + (255,))
draw_text(layer, (W / 2, 950), "plugin.json", int(40 * s) + 1, MUTED + (255,), bold=False)
chips = [
(260, 560, "Права", 0.9), (820, 600, "LihonT Guard", 1.2), (230, 1180, "Откат", 1.5),
(830, 1190, "Журнал", 1.8),
]
for x, y, text, t0 in chips:
chip(layer, x, y + math.sin(lt * 2 + x) * 8, text, pop(lt, t0), size=42)
chip(layer, W / 2, 1420, "Интернет только с вашего согласия", pop(lt, 2.4), size=36)
chip(layer, W / 2, 1540, "Лицензия и ИИ-метки на виду", pop(lt, 2.8), size=36)
chip(layer, W / 2, 1660, "Проверка перед установкой", pop(lt, 3.2), size=36, fill=PRIMARY, fg=BG)
def scene_shapes(layer, lt):
headline(layer, lt, "Форма аватарок", "Выбираете сами, видят все с модом")
kinds = P.SHAPE_KINDS
colors = [PRIMARY, PINK, (120, 200, 190), (255, 200, 120), CORAL, (160, 190, 255)]
for n, kind in enumerate(kinds):
row, col = divmod(n, 3)
k = pop(lt, 0.4 + n * 0.2)
wob = math.sin(lt * 2.4 + n) * 8
place(layer, P.shape_silhouette(kind, 260, colors[n]), 220 + col * 320, 700 + row * 340 + wob, k)
chip(layer, W / 2, 1480, "Круг · цветок · скруглённый", pop(lt, 1.8), size=36)
chip(layer, W / 2, 1600, "Шестиугольник · сердце · треугольник", pop(lt, 2.2), size=34)
chip(layer, W / 2, 1720, "Без мода — круг", pop(lt, 2.6), size=34, fill=PRIMARY, fg=BG)
def scene_settings(layer, lt):
headline(layer, lt, "Material 3", "Все настройки в одном стиле")
rows = [
("Призрак: истории", "Без отметки о просмотре"),
("Призрак: сообщения", "Без «прочитано»"),
("Свои пузыри", "Картинка и цвет текста"),
("Несколько фото", "До 9 в комментарии"),
("Меню сохранения", "Качество и только звук"),
]
card(layer, (80, 470, 1000, 470 + 5 * 220 + 40), radius=56)
for n, (title, sub) in enumerate(rows):
a = ease_out_cubic((lt - 0.3 - n * 0.15) / 0.4)
y = 590 + n * 220
dy = (1 - a) * 40
P.ImageDraw.Draw(layer, "RGBA").ellipse([130, y - 40 + dy, 210, y + 40 + dy], fill=(110, 60, 20, int(255 * a)))
draw_text(layer, (250, y - 24 + dy), title, 46, ON + (int(255 * a),), anchor="lm")
draw_text(layer, (250, y + 34 + dy), sub, 32, MUTED + (int(255 * a),), bold=False, anchor="lm")
if a > 0.6:
switch(layer, 880, y, ease_out_cubic((lt - 1.4 - n * 0.35) / 0.35))
chip(layer, W / 2, 1760, "И палитра, и окна, и значки", pop(lt, 2.4), size=36)
def scene_outro(layer, lt):
k = ease_out_back(lt / 0.8)
place(layer, ASSETS["blobs"][0], W / 2, 640, 1.3 * k)
place(layer, ASSETS["logo"], W / 2, 640, 0.40 * k * (1 + 0.03 * math.sin(lt * 4)), math.sin(lt * 2) * 3)
a = ease_out_cubic((lt - 0.4) / 0.5)
draw_text(layer, (W / 2, 960 + (1 - a) * 40), "LihonT 2 · Luna", 100, ON + (int(255 * a),))
b = ease_out_cubic((lt - 0.7) / 0.5)
draw_text(layer, (W / 2, 1075 + (1 - b) * 30), "Открытый код · лицензия VCBFU v2", 44, PRIMARY + (int(255 * b),), bold=False)
chip(layer, W / 2, 1290, "git.lihont.space", pop(lt, 1.0), size=54, fill=PRIMARY, fg=BG)
chip(layer, W / 2, 1430, "Telegram · @lihont", pop(lt, 1.3), size=54)
SCENE_DRAW = {name: globals()["scene_" + name] for name, _, _ in SCENES}
# ---------------------------------------------------------------- frames
def frame_at(t: float) -> Image.Image:
init_assets()
img = ASSETS["bg"].copy()
for n, blob_img in enumerate(ASSETS["blobs"]):
x = W * (0.2 + 0.6 * (0.5 + 0.5 * math.sin(t * (0.5 + n * 0.2) + n * 2)))
y = H * (0.25 + 0.5 * (0.5 + 0.5 * math.cos(t * (0.4 + n * 0.15) + n)))
img.alpha_composite(blob_img, (int(x - blob_img.width / 2), int(y - blob_img.height / 2)))
for x, y, speed, phase in ASSETS["motes"]:
yy = (y - t * 40 * speed) % (H + 100) - 50
img.alpha_composite(ASSETS["flower"], (int(x + math.sin(t * speed + phase) * 30), int(yy)))
for name, start, end in SCENES:
alpha = clamp((t - (start - FADE)) / (2 * FADE)) * clamp(((end + FADE) - t) / (2 * FADE))
if name == "intro":
alpha = clamp(((end + FADE) - t) / (2 * FADE))
if name == "outro":
alpha = clamp((t - (start - FADE)) / (2 * FADE))
if alpha <= 0.0:
continue
layer = Image.new("RGBA", (W, H), (0, 0, 0, 0))
SCENE_DRAW[name](layer, max(0.0, t - start))
if alpha < 1.0:
layer.putalpha(layer.getchannel("A").point(lambda v, a=alpha: 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, help="render one frame at this time (seconds) and stop")
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:]))
ffmpeg = shutil.which("ffmpeg") or "ffmpeg"
command = [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=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()