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>
533 lines
26 KiB
Python
533 lines
26 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
LihonT 2 «Luna» promo, second design: bright "sticker" style, more motion. 1080x1920, 30 fps, about 44 seconds.
|
||
|
||
A cream background with a drifting dot grid, thick ink outlines, hard shadows and saturated colours; scenes change with
|
||
a circle of the next colour opening over the last one. Nothing is a screenshot: the clock, the chat, the ghost, the
|
||
photos, the plugin pieces and the avatar shapes are all drawn here. The flames come from make_widget_preview.py (the
|
||
drawing the widget shows). The first promo (make_luna_promo.py) is not touched.
|
||
|
||
usage (from the repository root):
|
||
py -X utf8 -B scripts/make_luna_promo2.py # work/luna-promo/luna_promo_v2.mp4
|
||
py -X utf8 -B scripts/make_luna_promo2.py --still 14.0 # one frame
|
||
"""
|
||
|
||
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 (fonts, easing, shape outlines)
|
||
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_v2.mp4"
|
||
AUDIO = ROOT / "work" / "luna-promo" / "luna_audio_v2.wav"
|
||
|
||
INK = (34, 28, 46)
|
||
CREAM = (255, 244, 224)
|
||
CORAL = (255, 107, 107)
|
||
YELLOW = (255, 205, 60)
|
||
MINT = (94, 214, 170)
|
||
VIOLET = (150, 110, 255)
|
||
SKY = (90, 180, 255)
|
||
PINK = (255, 150, 200)
|
||
WHITE = (255, 255, 255)
|
||
CONFETTI = [CORAL, YELLOW, MINT, VIOLET, SKY, PINK]
|
||
|
||
SCENES = [
|
||
("intro", 0.0, 3.6, CREAM),
|
||
("flame", 3.6, 8.4, (255, 214, 150)),
|
||
("keeper", 8.4, 13.0, (190, 240, 220)),
|
||
("bubbles", 13.0, 18.2, (215, 200, 255)),
|
||
("ghost", 18.2, 22.8, (190, 225, 255)),
|
||
("photos", 22.8, 27.0, (255, 205, 225)),
|
||
("plugins", 27.0, 32.0, (255, 236, 150)),
|
||
("shapes", 32.0, 36.2, (200, 235, 255)),
|
||
("settings", 36.2, 40.6, (255, 226, 200)),
|
||
("outro", 40.6, 44.8, (255, 196, 176)),
|
||
]
|
||
DURATION = SCENES[-1][2]
|
||
FRAMES = int(round(DURATION * FPS))
|
||
WIPE = 0.55
|
||
|
||
clamp, ease_out_cubic, ease_out_back, pop = P.clamp, P.ease_out_cubic, P.ease_out_back, P.pop
|
||
ASSETS: dict = {}
|
||
|
||
|
||
# ---------------------------------------------------------------- drawing helpers
|
||
|
||
def stroke_text(layer, xy, s, size, fill=INK, outline=None, anchor="mm", bold=True, width=0):
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
if outline is not None and width:
|
||
d.text(xy, s, font=P.font(size, bold), fill=fill, anchor=anchor, stroke_width=width, stroke_fill=outline)
|
||
else:
|
||
d.text(xy, s, font=P.font(size, bold), fill=fill, anchor=anchor)
|
||
|
||
|
||
def sticker(layer, box, fill, radius=40, shadow=10, line=6):
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
x0, y0, x1, y1 = box
|
||
if shadow:
|
||
d.rounded_rectangle([x0 + shadow, y0 + shadow, x1 + shadow, y1 + shadow], radius=radius, fill=INK + (255,))
|
||
d.rounded_rectangle(box, radius=radius, fill=fill + (255,), outline=INK + (255,), width=line)
|
||
|
||
|
||
def label(layer, cx, cy, s, k=1.0, size=44, fill=WHITE, ink=INK):
|
||
"""A bouncy sticker with a word in it."""
|
||
if k <= 0.02:
|
||
return
|
||
f = P.font(max(8, size * k))
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
box = d.textbbox((0, 0), s, font=f, anchor="lt")
|
||
w, h = box[2] + 56 * k, box[3] + 36 * k
|
||
cx = max(w / 2 + 20, min(W - w / 2 - 20, cx))
|
||
sticker(layer, (cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2), fill, radius=int(h / 2), shadow=int(8 * k), line=max(2, int(5 * k)))
|
||
d.text((cx, cy + 2), s, font=f, fill=ink + (255,), anchor="mm")
|
||
|
||
|
||
def title(layer, lt, text, sub, color=INK, y=190):
|
||
"""Letters drop in one after another and settle with a bounce."""
|
||
f = P.font(110)
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
total = d.textlength(text, font=f)
|
||
x = W / 2 - total / 2
|
||
for n, ch in enumerate(text):
|
||
w = d.textlength(ch, font=f)
|
||
k = ease_out_back((lt - n * 0.035) / 0.45)
|
||
if k > 0.02 and ch != " ":
|
||
dy = (1 - k) * -160
|
||
d.text((x + w / 2, y + dy), ch, font=f, fill=color + (255,), anchor="mm", stroke_width=0)
|
||
x += w
|
||
b = ease_out_cubic((lt - 0.4) / 0.5)
|
||
d.text((W / 2, y + 100 + (1 - b) * 30), sub, font=P.font(46, False), fill=INK + (int(220 * b),), anchor="mm")
|
||
|
||
|
||
def burst(layer, cx, cy, lt, t0, seed=1, count=46, power=900):
|
||
"""Confetti thrown up from a point at time t0."""
|
||
dt = lt - t0
|
||
if dt < 0 or dt > 2.4:
|
||
return
|
||
rnd = random.Random(seed)
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
for _ in range(count):
|
||
a = rnd.uniform(-math.pi * 0.95, -math.pi * 0.05)
|
||
v = rnd.uniform(0.35, 1.0) * power
|
||
color = rnd.choice(CONFETTI)
|
||
spin = rnd.uniform(-8, 8)
|
||
size = rnd.uniform(10, 22)
|
||
x = cx + math.cos(a) * v * dt
|
||
y = cy + math.sin(a) * v * dt + 900 * dt * dt
|
||
alpha = int(255 * clamp(1.6 - dt / 1.5))
|
||
if rnd.random() < 0.5:
|
||
d.ellipse([x - size / 2, y - size / 2, x + size / 2, y + size / 2], fill=color + (alpha,))
|
||
else:
|
||
ang = spin * dt
|
||
pts = [(x + math.cos(ang + k * math.pi / 2) * size, y + math.sin(ang + k * math.pi / 2) * size * 0.5) for k in range(4)]
|
||
d.polygon(pts, fill=color + (alpha,))
|
||
|
||
|
||
def ring(layer, cx, cy, lt, t0, color=INK, size=300):
|
||
dt = (lt - t0) / 0.7
|
||
if 0 <= dt <= 1:
|
||
r = size * ease_out_cubic(dt)
|
||
ImageDraw.Draw(layer, "RGBA").ellipse([cx - r, cy - r, cx + r, cy + r], outline=color + (int(255 * (1 - dt)),), width=10)
|
||
|
||
|
||
def ghost(size, alpha=1.0, blink=False):
|
||
s = size * 3
|
||
layer = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(layer)
|
||
body = WHITE + (255,)
|
||
d.ellipse([s * 0.2, s * 0.1, s * 0.8, s * 0.7], fill=body, outline=INK + (255,), width=14)
|
||
d.rectangle([s * 0.2, s * 0.4, s * 0.8, s * 0.82], fill=body)
|
||
d.line([(s * 0.2, s * 0.4), (s * 0.2, s * 0.82)], fill=INK + (255,), width=14)
|
||
d.line([(s * 0.8, s * 0.4), (s * 0.8, s * 0.82)], fill=INK + (255,), width=14)
|
||
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], fill=body, outline=INK + (255,), width=14)
|
||
d.rectangle([s * 0.215, s * 0.74, s * 0.785, s * 0.82], fill=body)
|
||
for ex in (0.38, 0.62):
|
||
if blink:
|
||
d.line([(s * ex - s * 0.05, s * 0.41), (s * ex + s * 0.05, s * 0.41)], fill=INK + (255,), width=14)
|
||
else:
|
||
d.ellipse([s * ex - s * 0.045, s * 0.35, s * ex + s * 0.045, s * 0.47], fill=INK + (255,))
|
||
d.ellipse([s * 0.46, s * 0.52, s * 0.54, s * 0.6], fill=INK + (255,))
|
||
img = layer.resize((size, size), Image.Resampling.LANCZOS)
|
||
if alpha < 1.0:
|
||
img.putalpha(img.getchannel("A").point(lambda v: int(v * alpha)))
|
||
return img
|
||
|
||
|
||
def switch(layer, cx, cy, on):
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
track = tuple(int(WHITE[n] * (1 - on) + MINT[n] * on) for n in range(3))
|
||
d.rounded_rectangle([cx - 70, cy - 40, cx + 70, cy + 40], radius=40, fill=track + (255,), outline=INK + (255,), width=6)
|
||
kx = cx - 30 + 60 * on
|
||
d.ellipse([kx - 28, cy - 28, kx + 28, cy + 28], fill=INK + (255,))
|
||
|
||
|
||
def picture(w, h, c1, c2, radius=40):
|
||
img = P.Image.new("RGB", (w, h))
|
||
d = ImageDraw.Draw(img)
|
||
for i in range(w):
|
||
k = i / max(1, w - 1)
|
||
d.line([(i, 0), (i, h)], fill=tuple(int(c1[n] + (c2[n] - c1[n]) * k) for n in range(3)))
|
||
img = img.convert("RGBA")
|
||
flower = P.flower(80, (255, 255, 255, 110))
|
||
for x in range(-10, w - 70, 120):
|
||
for y in range(-10 + (x // 120 % 2) * 55, h - 70, 110):
|
||
img.alpha_composite(flower, (x, y))
|
||
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)
|
||
img.putalpha(mask.resize((w, h), Image.Resampling.LANCZOS))
|
||
d = ImageDraw.Draw(img)
|
||
d.rounded_rectangle([1, 1, w - 2, h - 2], radius=radius, outline=INK + (255,), width=5)
|
||
return img
|
||
|
||
|
||
def place(layer, img, cx, cy, scale=1.0, angle=0.0):
|
||
P.place(layer, img, cx, cy, scale, angle)
|
||
|
||
|
||
def init_assets():
|
||
if ASSETS:
|
||
return
|
||
ASSETS["dots"] = Image.new("RGBA", (W + 160, H + 160), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(ASSETS["dots"])
|
||
for x in range(0, W + 160, 80):
|
||
for y in range(0, H + 160, 80):
|
||
d.ellipse([x - 5, y - 5, x + 5, y + 5], fill=INK + (34,))
|
||
ASSETS["logo"] = Image.open(P.LOGO).convert("RGBA")
|
||
ASSETS["flame_lit"] = [WP.render(True, n) for n in range(4)]
|
||
ASSETS["flame_grey"] = WP.render(False)
|
||
ASSETS["dark"] = picture(560, 150, (80, 70, 220), (30, 20, 120))
|
||
ASSETS["light"] = picture(560, 150, (255, 230, 170), (255, 170, 190))
|
||
ASSETS["mine"] = picture(520, 150, (170, 80, 220), (110, 40, 170))
|
||
|
||
|
||
# ---------------------------------------------------------------- scenes
|
||
|
||
def scene_intro(layer, lt):
|
||
k = ease_out_back(lt / 0.9)
|
||
place(layer, ASSETS["logo"], W / 2, 760, 0.5 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 360)
|
||
burst(layer, W / 2, 760, lt, 0.6, seed=4)
|
||
title(layer, max(0.0, lt - 0.9), "LihonT 2", "Что нового в Luna", y=1230)
|
||
label(layer, W / 2, 1480, "релиз", pop(lt, 1.8), size=64, fill=YELLOW)
|
||
|
||
|
||
def scene_flame(layer, lt):
|
||
title(layer, lt, "Живой огонёк", "Виджет серии")
|
||
phase = int(lt / 0.2) % 4
|
||
lit = ASSETS["flame_lit"][phase]
|
||
# four sizes, each popping in and breathing
|
||
spots = [(250, 800, 0.46, "1×1"), (700, 780, 0.62, "2×2"), (320, 1240, 0.9, "3×3"), (820, 1260, 0.66, "4×4")]
|
||
for n, (x, y, s, name) in enumerate(spots):
|
||
k = pop(lt, 0.5 + n * 0.3, 0.6)
|
||
breathe = 1 + 0.04 * math.sin(lt * 5 + n)
|
||
flame = lit if n != 1 or lt < 3.0 else ASSETS["flame_grey"]
|
||
place(layer, flame, x, y + math.sin(lt * 2 + n) * 10, s * k * breathe, math.sin(lt * 3 + n) * 4)
|
||
label(layer, x, y + 200 * s + 70, name, pop(lt, 0.8 + n * 0.3), size=40, fill=YELLOW if n % 2 else WHITE)
|
||
ring(layer, x, y, lt, 0.5 + n * 0.3, size=210 * s + 60)
|
||
rnd = random.Random(8)
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
for _ in range(26): # sparks drifting up
|
||
x0, ph, sp = rnd.uniform(80, 1000), rnd.uniform(0, 6), rnd.uniform(0.6, 1.4)
|
||
y = H - ((lt * 220 * sp + ph * 200) % (H + 100))
|
||
r = 6 + 6 * math.sin(lt * 4 + ph) ** 2
|
||
d.ellipse([x0 + math.sin(lt * sp + ph) * 30 - r, y - r, x0 + math.sin(lt * sp + ph) * 30 + r, y + r], fill=CORAL + (170,))
|
||
label(layer, W / 2, 1620, "Горит оранжевый, пора писать серый", pop(lt, 2.2), size=36, fill=WHITE)
|
||
|
||
|
||
def clock(layer, cx, cy, r, t):
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
d.ellipse([cx - r + 10, cy - r + 10, cx + r + 10, cy + r + 10], fill=INK + (255,))
|
||
d.ellipse([cx - r, cy - r, cx + r, cy + r], fill=WHITE + (255,), outline=INK + (255,), width=8)
|
||
for k in range(12):
|
||
a = k * math.pi / 6
|
||
d.line([(cx + math.cos(a) * r * 0.82, cy + math.sin(a) * r * 0.82), (cx + math.cos(a) * r * 0.93, cy + math.sin(a) * r * 0.93)], fill=INK + (255,), width=6)
|
||
minute = (1 - ease_out_cubic(t / 2.0)) * math.pi * 6 + 0.0 # spins down to 12:00
|
||
hour = -math.pi / 2 + (1 - ease_out_cubic(t / 2.0)) * math.pi * 1.0
|
||
d.line([(cx, cy), (cx + math.cos(hour) * r * 0.5, cy + math.sin(hour) * r * 0.5)], fill=INK + (255,), width=14)
|
||
d.line([(cx, cy), (cx + math.cos(minute - math.pi / 2) * r * 0.76, cy + math.sin(minute - math.pi / 2) * r * 0.76)], fill=CORAL + (255,), width=10)
|
||
d.ellipse([cx - 14, cy - 14, cx + 14, cy + 14], fill=INK + (255,))
|
||
|
||
|
||
def scene_keeper(layer, lt):
|
||
title(layer, lt, "Автопродление", "Сам, в нужное время")
|
||
clock(layer, 540, 640, 170, max(0.0, lt - 0.3))
|
||
label(layer, 540, 880, "12:00", pop(lt, 1.8), size=72, fill=YELLOW)
|
||
names = [("Мама", CORAL), ("Друг", SKY), ("Класс", VIOLET), ("Сестра", MINT)]
|
||
t_flip = 2.4
|
||
for n, (name, color) in enumerate(names):
|
||
k = ease_out_back((lt - 0.5 - n * 0.18) / 0.55)
|
||
side = -1 if n % 2 == 0 else 1
|
||
x_off = (1 - k) * 900 * side
|
||
y = 1060 + n * 170
|
||
sticker(layer, (90 + x_off, y - 70, 990 + x_off, y + 70), WHITE, radius=44)
|
||
ImageDraw.Draw(layer, "RGBA").ellipse([120 + x_off, y - 50, 220 + x_off, y + 50], fill=color + (255,), outline=INK + (255,), width=6)
|
||
stroke_text(layer, (250 + x_off, y), name, 46, INK, anchor="lm")
|
||
t_n = t_flip + n * 0.35
|
||
flipped = lt > t_n
|
||
flame = ASSETS["flame_lit"][int(lt / 0.2 + n) % 4] if flipped else ASSETS["flame_grey"]
|
||
pulse = 1 + (0.5 * max(0.0, 1 - (lt - t_n) * 3) if flipped else 0)
|
||
place(layer, flame, 880 + x_off, y, 0.22 * pulse)
|
||
if flipped:
|
||
ring(layer, 880, y, lt, t_n, color=CORAL, size=120)
|
||
burst(layer, 540, 640, lt, t_flip, seed=6, count=30, power=700)
|
||
|
||
|
||
def scene_bubbles(layer, lt):
|
||
title(layer, lt, "Свои пузыри", "Любая картинка вместо фона")
|
||
items = [
|
||
(ASSETS["dark"], 100, 560, "Привет! Картинка", WHITE, 0.6, -1),
|
||
(ASSETS["mine"], 460, 760, "Видно всё", WHITE, 1.3, 1),
|
||
(ASSETS["light"], 100, 960, "На светлой чёрный", INK, 2.0, -1),
|
||
(ASSETS["dark"], 100, 1160, "На тёмной белый", WHITE, 2.7, -1),
|
||
]
|
||
for img, x, y, text, ink, t0, side in items:
|
||
k = ease_out_back((lt - t0) / 0.5)
|
||
if k <= 0.02:
|
||
if t0 - 0.5 < lt < t0: # three typing dots before the message arrives
|
||
for i in range(3):
|
||
r = 12 + 8 * max(0.0, math.sin(lt * 10 - i * 0.9))
|
||
cx = (x + 60 if side < 0 else 960 - 60) + i * 40 * (1 if side < 0 else -1)
|
||
ImageDraw.Draw(layer, "RGBA").ellipse([cx - r, y + 75 - r, cx + r, y + 75 + r], fill=INK + (255,))
|
||
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 + (1 - k) * 80)))
|
||
if k > 0.8:
|
||
stroke_text(layer, (x + 44, y + 75), text, 46, ink, anchor="lm")
|
||
# a colour palette that recolours the last message's text
|
||
colors = [WHITE, YELLOW, MINT, PINK, SKY]
|
||
for i, c in enumerate(colors):
|
||
k = pop(lt, 3.4 + i * 0.12)
|
||
cx = 220 + i * 150
|
||
r = 46 * clamp(k, 0, 1.2)
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
d.ellipse([cx - r, 1420 - r, cx + r, 1420 + r], fill=c + (255,), outline=INK + (255,), width=6)
|
||
pick = int(max(0.0, lt - 4.0) / 0.35) % len(colors) if lt > 4.0 else 0
|
||
if lt > 3.4:
|
||
ring(layer, 220 + pick * 150, 1420, lt, 4.0 + int(max(0.0, lt - 4.0) / 0.35) * 0.35, color=INK, size=90)
|
||
label(layer, 540, 1590, "Цвет текста выбираете сами", pop(lt, 3.6), size=36, fill=YELLOW)
|
||
label(layer, 540, 1700, "Для каждого человека и для незнакомцев", pop(lt, 4.0), size=32)
|
||
|
||
|
||
def scene_ghost(layer, lt):
|
||
title(layer, lt, "Режим призрака", "Смотрите и читайте незаметно")
|
||
fade = 0.55 + 0.45 * math.sin(lt * 2.0) # fades in and out like a real ghost
|
||
bob = math.sin(lt * 2.2) * 22
|
||
blink = (lt % 2.4) > 2.25
|
||
for i in range(3): # trail
|
||
place(layer, ghost(300, alpha=0.18 * fade, blink=blink), W / 2 - 60 * (i + 1) * math.sin(lt), 760 + bob + 40 * (i + 1), 1.0)
|
||
place(layer, ghost(360, alpha=fade, blink=blink), W / 2, 760 + bob, ease_out_back(lt / 0.8))
|
||
sticker(layer, (90, 1060, 990, 1260), WHITE, radius=48)
|
||
stroke_text(layer, (150, 1120), "Истории", 50, INK, anchor="lm")
|
||
stroke_text(layer, (150, 1200), "Автор не увидит вас в зрителях", 32, INK, bold=False, anchor="lm")
|
||
sticker(layer, (90, 1300, 990, 1500), WHITE, radius=48)
|
||
stroke_text(layer, (150, 1360), "Чаты", 50, INK, anchor="lm")
|
||
stroke_text(layer, (150, 1440), "«Прочитано» не отправляется", 32, INK, bold=False, anchor="lm")
|
||
for y, t0 in ((1160, 1.2), (1400, 1.9)):
|
||
on = ease_out_cubic((lt - t0) / 0.4)
|
||
switch(layer, 860, y, on)
|
||
if on > 0.9:
|
||
ring(layer, 860, y, lt, t0 + 0.35, color=MINT, size=110)
|
||
label(layer, W / 2, 1650, "Включается в «Приватность»", pop(lt, 2.6), size=36, fill=YELLOW)
|
||
|
||
|
||
def scene_photos(layer, lt):
|
||
title(layer, lt, "До 9 фото", "в одном комментарии")
|
||
palette = [(CORAL, YELLOW), (SKY, VIOLET), (MINT, SKY)]
|
||
rnd = random.Random(2)
|
||
for n in range(9):
|
||
row, col = divmod(n, 3)
|
||
t0 = 0.5 + n * 0.22
|
||
k = clamp((lt - t0) / 0.7)
|
||
if k <= 0:
|
||
continue
|
||
c1, c2 = palette[(row + col) % 3]
|
||
tile = picture(250, 250, c1, c2, radius=40)
|
||
tx, ty = 240 + col * 300, 660 + row * 300
|
||
edge = rnd.choice([(-300, -300), (W + 300, -200), (-300, H - 400), (W + 300, H - 300)])
|
||
e = ease_out_cubic(k)
|
||
x = edge[0] + (tx - edge[0]) * e
|
||
y = edge[1] + (ty - edge[1]) * e - math.sin(k * math.pi) * 200
|
||
place(layer, tile, x, y, 0.6 + 0.4 * e, (1 - e) * 360 * (1 if n % 2 else -1))
|
||
if k >= 1 and lt - t0 - 0.7 < 0.5:
|
||
ring(layer, tx, ty, lt, t0 + 0.7, color=INK, size=160)
|
||
sticker(layer, (80, 1600, 1000, 1760), WHITE, radius=80)
|
||
stroke_text(layer, (150, 1680), "Написать комментарий…", 40, INK, bold=False, anchor="lm")
|
||
count = min(9, int(max(0.0, lt - 0.5) / 0.22) + 1)
|
||
label(layer, 860, 1680, "%d/9" % count, 1.0, size=40, fill=YELLOW)
|
||
|
||
|
||
def scene_plugins(layer, lt):
|
||
title(layer, lt, "Плагины .ltp", "Свои дополнения без кода")
|
||
k = ease_out_back((lt - 0.2) / 0.8)
|
||
place(layer, ASSETS["logo"], 540, 760, 0.0001)
|
||
# the file card
|
||
x0, y0, x1, y1 = 540 - 190 * k, 760 - 240 * k, 540 + 190 * k, 760 + 240 * k
|
||
sticker(layer, (x0, y0, x1, y1), WHITE, radius=50)
|
||
stroke_text(layer, (540, 740), ".ltp", int(120 * k) + 1, VIOLET, outline=INK, width=6)
|
||
stroke_text(layer, (540, 860), "plugin.json", int(38 * k) + 1, INK, bold=False)
|
||
# rule blocks fly in and snap to the card
|
||
blocks = [("Права", CORAL, (180, 480), 1.0), ("Защитник", MINT, (900, 520), 1.4), ("Откат", SKY, (170, 1060), 1.8), ("Журнал", PINK, (910, 1040), 2.2)]
|
||
for text, color, (bx, by), t0 in blocks:
|
||
e = ease_out_cubic((lt - t0) / 0.6)
|
||
if e <= 0:
|
||
continue
|
||
sx, sy = (bx - 600 if bx < 540 else bx + 600), by - 300
|
||
x = sx + (bx - sx) * e + math.sin(lt * 2 + bx) * 6 * e
|
||
y = sy + (by - sy) * e
|
||
label(layer, x, y, text, 1.0, size=46, fill=color)
|
||
if lt - t0 > 0.6 and lt - t0 < 0.9:
|
||
ring(layer, bx, by, lt, t0 + 0.6, color=INK, size=120)
|
||
# shield with a check that draws itself
|
||
sh = pop(lt, 2.6)
|
||
if sh > 0.02:
|
||
cx, cy = 540, 1280
|
||
d = ImageDraw.Draw(layer, "RGBA")
|
||
pts = [(cx - 90 * sh, cy - 100 * sh), (cx + 90 * sh, cy - 100 * sh), (cx + 90 * sh, cy + 10 * sh), (cx, cy + 110 * sh), (cx - 90 * sh, cy + 10 * sh)]
|
||
d.polygon([(x + 8, y + 8) for x, y in pts], fill=INK + (255,))
|
||
d.polygon(pts, fill=MINT + (255,), outline=INK + (255,))
|
||
d.line(pts + [pts[0]], fill=INK + (255,), width=8, joint="curve")
|
||
prog = clamp((lt - 3.0) / 0.5)
|
||
tick = [(cx - 40, cy - 5), (cx - 10, cy + 30), (cx + 45, cy - 40)]
|
||
if prog > 0:
|
||
seg = prog * 2
|
||
d.line(tick[:2] if seg < 1 else tick[:2], fill=INK + (255,), width=14)
|
||
if seg > 1:
|
||
d.line([tick[1], (tick[1][0] + (tick[2][0] - tick[1][0]) * (seg - 1), tick[1][1] + (tick[2][1] - tick[1][1]) * (seg - 1))], fill=INK + (255,), width=14)
|
||
label(layer, 540, 1490, "Интернет только с вашего согласия", pop(lt, 3.2), size=36, fill=WHITE)
|
||
label(layer, 540, 1600, "Проверка перед установкой", pop(lt, 3.6), size=36, fill=YELLOW)
|
||
label(layer, 540, 1710, "Лицензия и метки ИИ на виду", pop(lt, 4.0), size=34, fill=WHITE)
|
||
|
||
|
||
def scene_shapes(layer, lt):
|
||
title(layer, lt, "Форма аватарок", "Выбираете сами")
|
||
kinds = P.SHAPE_KINDS
|
||
colors = [VIOLET, PINK, MINT, YELLOW, CORAL, SKY]
|
||
# the big avatar morphs through all the shapes
|
||
idx = int(lt / 0.7) % len(kinds)
|
||
part = (lt / 0.7) % 1.0
|
||
squash = 1 + 0.12 * math.sin(part * math.pi)
|
||
big = P.shape_silhouette(kinds[idx], 380, colors[idx])
|
||
outline = P.shape_silhouette(kinds[idx], 400, INK)
|
||
place(layer, outline, 540 + 8, 720 + 8, squash)
|
||
place(layer, big, 540, 720, squash * 0.98, math.sin(lt * 2) * 5)
|
||
for n, kind in enumerate(kinds):
|
||
k = pop(lt, 0.6 + n * 0.18)
|
||
place(layer, P.shape_silhouette(kind, 150, colors[n]), 140 + n * 160, 1130 + math.sin(lt * 4 + n) * 12, k * (1.15 if n == idx else 1.0))
|
||
label(layer, W / 2, 1330, "Круг · цветок · сердце · треугольник", pop(lt, 1.8), size=34)
|
||
label(layer, W / 2, 1450, "Её видят все, у кого есть мод", pop(lt, 2.3), size=36, fill=YELLOW)
|
||
label(layer, W / 2, 1570, "Без мода — обычный круг", pop(lt, 2.8), size=34)
|
||
|
||
|
||
def scene_settings(layer, lt):
|
||
title(layer, lt, "Material 3", "Все настройки в одном стиле")
|
||
rows = [("Призрак: истории", CORAL), ("Призрак: сообщения", SKY), ("Свои пузыри", VIOLET), ("Несколько фото", MINT), ("Меню сохранения", YELLOW)]
|
||
for n, (name, color) in enumerate(rows):
|
||
k = ease_out_back((lt - 0.4 - n * 0.16) / 0.5)
|
||
x_off = (1 - k) * (900 if n % 2 else -900)
|
||
y = 560 + n * 215
|
||
sticker(layer, (80 + x_off, y - 85, 1000 + x_off, y + 85), WHITE, radius=48)
|
||
ImageDraw.Draw(layer, "RGBA").ellipse([120 + x_off, y - 45, 210 + x_off, y + 45], fill=color + (255,), outline=INK + (255,), width=6)
|
||
stroke_text(layer, (250 + x_off, y), name, 46, INK, anchor="lm")
|
||
on = ease_out_cubic((lt - 1.6 - n * 0.4) / 0.35)
|
||
switch(layer, 880 + x_off, y, on)
|
||
if on > 0.95 and lt - (1.6 + n * 0.4 + 0.35) < 0.5:
|
||
ring(layer, 880, y, lt, 1.6 + n * 0.4 + 0.3, color=MINT, size=100)
|
||
label(layer, W / 2, 1750, "И палитра, и окна, и значки", pop(lt, 3.6), size=36, fill=YELLOW)
|
||
|
||
|
||
def scene_outro(layer, lt):
|
||
k = ease_out_back(lt / 0.8)
|
||
place(layer, ASSETS["logo"], W / 2, 620, 0.46 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 300)
|
||
burst(layer, W / 2, 620, lt, 0.5, seed=9, count=60, power=1000)
|
||
title(layer, max(0.0, lt - 0.5), "LihonT 2 · Luna", "Открытый код · лицензия VCBFU v2", y=1000)
|
||
bounce = lambda t0: abs(math.sin((lt - t0) * 3)) * 14 if lt > t0 else 0 # noqa: E731
|
||
label(layer, W / 2, 1290 - bounce(1.2), "git.lihont.space", pop(lt, 1.2), size=60, fill=YELLOW)
|
||
label(layer, W / 2, 1440 - bounce(1.5), "Telegram · @lihont", pop(lt, 1.5), size=60, fill=WHITE)
|
||
|
||
|
||
SCENE_DRAW = {name: globals()["scene_" + name] for name, _, _, _ in SCENES}
|
||
|
||
|
||
# ---------------------------------------------------------------- frames
|
||
|
||
def frame_at(t: float) -> Image.Image:
|
||
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: # the previous colour is still there; the new one opens as a circle
|
||
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(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, 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 / ("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:]))
|
||
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()
|