A pair of people can have a kitten, a puppy or a lion cub in place of TikTok's streak creature: it grows with the days of the streak (cub, teen, adult, elder), goes grey while the streak is about to burn out, can be dragged in the chat and is also shown on the big streak screen. An animal is given by a link (lihont.space/pet) that the friend accepts. The drawings are made by scripts/make_pet_designs.py and served as strips of frames. Also here: the promo video scripts (make_pet_video.py on top of make_store_video.py), a retry pause for strips that failed to load, stricter checks in the answer to a gift. Work in progress: the gift service is not switched on for everyone yet and there is no public build with the animals. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
446 lines
23 KiB
Python
446 lines
23 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
LihonT 3 · Luna pre-alpha: the promo video of the Серийчик animals, in the same white, light style as the Store video
|
||
(scripts/make_store_video.py, whose drawing helpers and soundtrack it uses; the events here fall on the same moments as the sounds of
|
||
work/music/store.mp3: click, drop, ticking, ding, pop, tiles, boing and mew, riser, three blups, sparkle, three word lines, title, logo).
|
||
|
||
Only our own material: the animals drawn by scripts/make_pet_designs.py, invented screens with no names and no message text.
|
||
|
||
py -X utf8 -B scripts/make_pet_video.py # work/pet-video/lihont3_pets.mp4
|
||
py -X utf8 -B scripts/make_pet_video.py --still 7.9 16 # single frames
|
||
py -X utf8 -B scripts/make_pet_video.py --sheet # a contact sheet
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import math
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
from functools import lru_cache
|
||
from multiprocessing import Pool
|
||
from pathlib import Path
|
||
|
||
from PIL import Image, ImageDraw, ImageFilter
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||
import make_pet_designs as D # noqa: E402
|
||
import make_store_video as V # noqa: E402
|
||
from make_store_video import (GREY, INK, VIOLET, burst, card, clamp, cursor_sprite, disc, draw_check, font, in_out, lerp, out_back, # noqa: E402
|
||
out_cubic, pill, put, put_c, ripple, rr, seg, text)
|
||
|
||
OUT_DIR = V.ROOT / "work" / "pet-video"
|
||
SPRITES = OUT_DIR / "sprites"
|
||
BASE = 720 # the side the animals are drawn at
|
||
W, H, FPS = 1920, 1080, 30
|
||
CX, CY = W // 2, H // 2
|
||
VERT = False
|
||
|
||
|
||
def set_format(vertical: bool) -> None:
|
||
"""Landscape 1920x1080 or portrait 1080x1920: the scenes read the size, the middle and VERT from here."""
|
||
global W, H, CX, CY, VERT
|
||
VERT = bool(vertical)
|
||
W, H = (1080, 1920) if VERT else (1920, 1080)
|
||
CX, CY = W // 2, H // 2
|
||
V.set_format(VERT)
|
||
|
||
|
||
PASTEL = {"cat": (255, 232, 214), "dog": (222, 234, 255), "lion": (255, 242, 204)}
|
||
NAMES = {"cat": "Котёнок", "dog": "Щенок", "lion": "Львёнок"}
|
||
PINK = (255, 99, 150)
|
||
# every animal that is shown: (kind, stage, grey)
|
||
CAST = [("cat", "cub", False), ("dog", "cub", False), ("lion", "cub", False), ("cat", "teen", False), ("cat", "adult", False),
|
||
("cat", "elder", False), ("cat", "elder", True)]
|
||
S: list = []
|
||
|
||
|
||
def prepare() -> None:
|
||
"""Draws every frame of every animal of the cast once, large, into work/pet-video/sprites."""
|
||
SPRITES.mkdir(parents=True, exist_ok=True)
|
||
D.SIZE, D.W = BASE, BASE * D.S
|
||
for kind, stage, sad in CAST:
|
||
for frame in range(D.FRAMES):
|
||
path = SPRITES / ("%s_%s_%d_%02d.png" % (kind, stage, int(sad), frame))
|
||
if not path.exists():
|
||
D.animal(kind, stage, sad=sad, frame=frame).save(path)
|
||
|
||
|
||
@lru_cache(maxsize=40)
|
||
def sprite(kind: str, stage: str, sad: bool, frame: int) -> Image.Image:
|
||
return Image.open(SPRITES / ("%s_%s_%d_%02d.png" % (kind, stage, int(sad), frame))).convert("RGBA")
|
||
|
||
|
||
def pet(t: float, kind: str, stage: str = "cub", sad: bool = False) -> Image.Image:
|
||
return sprite(kind, stage, sad, int(t * 12) % D.FRAMES)
|
||
|
||
|
||
@lru_cache(maxsize=8)
|
||
def ground_shadow(w: int) -> Image.Image:
|
||
layer = Image.new("RGBA", (w + 80, w // 4 + 80), (0, 0, 0, 0))
|
||
ImageDraw.Draw(layer).ellipse([40, 40, w + 40, w // 4 + 40], fill=(30, 20, 50, 60))
|
||
return layer.filter(ImageFilter.GaussianBlur(16))
|
||
|
||
|
||
def put_pet(img, t, kind, stage, cx, cy, size, alpha=1.0, sad=False, shadow=True, angle=0.0):
|
||
"""An animal `size` pixels high with its middle at (cx, cy), standing on a soft shadow."""
|
||
if size < 8 or alpha <= 0.003:
|
||
return
|
||
if shadow:
|
||
put_c(img, ground_shadow(360), cx, cy + size * 0.4, size / 620, alpha)
|
||
put_c(img, pet(t, kind, stage, sad), cx, cy, size / BASE, alpha, angle)
|
||
|
||
|
||
@lru_cache(maxsize=4)
|
||
def gift_box(size: int) -> Image.Image:
|
||
k = 3
|
||
s = size * k
|
||
layer = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(layer)
|
||
d.rounded_rectangle([s * 0.14, s * 0.4, s * 0.86, s * 0.92], radius=s * 0.07, fill=PINK + (255,))
|
||
d.rounded_rectangle([s * 0.08, s * 0.26, s * 0.92, s * 0.44], radius=s * 0.06, fill=(255, 130, 172, 255))
|
||
d.rectangle([s * 0.44, s * 0.26, s * 0.56, s * 0.92], fill=(255, 214, 90, 255))
|
||
for sx in (-1, 1): # the bow
|
||
d.ellipse([s * 0.5 + sx * s * 0.02 - (s * 0.2 if sx < 0 else 0), s * 0.08, s * 0.5 + sx * s * 0.02 + (s * 0.2 if sx > 0 else 0), s * 0.28],
|
||
fill=(255, 214, 90, 255))
|
||
d.ellipse([s * 0.44, s * 0.15, s * 0.56, s * 0.27], fill=(240, 180, 50, 255))
|
||
return layer.resize((size, size), Image.Resampling.LANCZOS)
|
||
|
||
|
||
def arc(img, cx, cy, r, k, color, width=16):
|
||
"""A ring that fills clockwise from the top up to k."""
|
||
q = 3
|
||
side = (r * 2 + width * 2) * q
|
||
layer = Image.new("RGBA", (side, side), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(layer)
|
||
box = [width * q, width * q, side - width * q, side - width * q]
|
||
d.arc(box, 0, 360, fill=(232, 232, 238, 255), width=width * q)
|
||
if k > 0.005:
|
||
d.arc(box, -90, -90 + 360 * clamp(k), fill=tuple(color) + (255,), width=width * q)
|
||
small = layer.resize((side // q, side // q), Image.Resampling.LANCZOS)
|
||
put(img, small, cx - small.width / 2, cy - small.height / 2)
|
||
|
||
|
||
# ---------------------------------------------------------------- scenes
|
||
|
||
def scene_link(img, t):
|
||
"""A pill in which the gift link types itself; the cursor comes and clicks it on the strong beat."""
|
||
click = S[1]
|
||
if t >= click + 0.45:
|
||
return
|
||
intro = out_back(seg(t, 0.1, 0.7))
|
||
gone = seg(t, click + 0.1, click + 0.45)
|
||
press = 1 - 0.06 * clamp(1 - abs(t - click) / 0.1)
|
||
w, h = 820, 120
|
||
full = "lihont.space/pet · котёнок для друга"
|
||
shown = full[:int(len(full) * seg(t, 0.7, 2.2))]
|
||
layer = Image.new("RGBA", (w + 120, h + 120), (0, 0, 0, 0))
|
||
layer.alpha_composite(card(w, h, h // 2, (255, 255, 255), blur=30, dy=12, alpha=44))
|
||
d = ImageDraw.Draw(layer)
|
||
cx0, cy0 = 60 + 70, 60 + h // 2
|
||
d.ellipse([cx0 - 38, cy0 - 38, cx0 + 38, cy0 + 38], fill=PINK + (255,))
|
||
layer.alpha_composite(gift_box(52), (cx0 - 26, cy0 - 28))
|
||
d.text((60 + 150, 60 + h // 2 - 1), shown, font=font(40, "semi"), fill=INK + (255,), anchor="lm")
|
||
if len(shown) < len(full) and int(t * 3) % 2 == 0: # the caret
|
||
x = 60 + 150 + d.textlength(shown, font=font(40, "semi")) + 4
|
||
d.line([(x, 60 + 32), (x, 60 + h - 32)], fill=INK + (255,), width=3)
|
||
ks = 0.88 if VERT else 1.0
|
||
put_c(img, layer, CX, CY, lerp(0.9, 1.0, intro) * press * (1 + 0.25 * gone) * ks, clamp(intro * 1.3) * (1 - gone))
|
||
ripple(img, CX + 50, CY + 20, t, click, PINK, 120)
|
||
k = in_out(seg(t, 1.9, click - 0.1))
|
||
cx, cy = lerp(W - 120, CX + 50, k) - math.sin(k * math.pi) * 90, lerp(H - 160 if VERT else H + 80, CY + 26, k)
|
||
put_c(img, cursor_sprite(), cx + 10, cy + 16, 1.0 - 0.08 * clamp(1 - abs(t - click) / 0.1), out_cubic(seg(t, 1.8, 2.2)))
|
||
|
||
|
||
def scene_gift(img, t): # noqa: C901
|
||
"""The gift window: "Принять" is pressed, the ring fills, a check is drawn, the window slides down and the kitten pops out."""
|
||
a, press_t, drop, ding = S[1] + 0.2, S[1] + 1.25, S[2], S[3]
|
||
if t < a or t > S[4] + 0.75:
|
||
return
|
||
down = in_out(seg(t, ding + 0.5, ding + 1.2))
|
||
grow = out_back(seg(t, a, a + 0.55), 1.2)
|
||
w, h = 640, 720
|
||
wy = CY + down * (H * 0.75)
|
||
if down < 1:
|
||
put_c(img, card(w, h, 56, (255, 255, 255), blur=44, dy=22, alpha=56), CX, wy, lerp(0.4, 1.0, grow), clamp(grow * 1.4))
|
||
show = seg(t, a + 0.3, a + 0.6)
|
||
text(img, (CX, wy - 270), "Вам дарят котёнка", 46, "bold", INK, "mm", alpha=show)
|
||
text(img, (CX, wy - 212), "он поселится в вашем общем чате", 28, "reg", GREY, "mm", alpha=show)
|
||
mid = wy - 30
|
||
if t < drop: # the box, shaking after the press
|
||
shake = math.sin((t - press_t) * 40) * 7 * seg(t, press_t, press_t + 0.2) if t > press_t else 0
|
||
put_c(img, gift_box(300), CX, mid + math.sin(t * 3) * 6, out_back(show) * (1 - 0.3 * seg(t, drop - 0.12, drop)), show, shake)
|
||
elif t < ding: # the ring fills while the mallets tick
|
||
arc(img, CX, mid, 110, in_out(seg(t, drop, ding - 0.05)), PINK)
|
||
put_pet(img, t, "cat", "cub", CX, mid, 150 * out_back(seg(t, drop, drop + 0.3)), shadow=False)
|
||
burst(img, CX, mid, t, drop, seed=3, n=18, power=300, life=0.7)
|
||
else: # the check
|
||
pop = out_back(seg(t, ding, ding + 0.3))
|
||
put_c(img, disc(240, PINK), CX, mid, pop)
|
||
draw_check(img, CX, mid + 4, 110, out_cubic(seg(t, ding + 0.05, ding + 0.4)))
|
||
burst(img, CX, mid, t, ding + 0.05, seed=5, n=46, power=640, life=1.2)
|
||
# the button
|
||
by = wy + 250
|
||
pressed = 1 - 0.07 * clamp(1 - abs(t - press_t) / 0.12)
|
||
if t < drop:
|
||
pill(img, CX, by, "Принять", fill=INK, size=34, alpha=show, scale=pressed)
|
||
elif t < ding:
|
||
pill(img, CX, by, "Зверь уже едет…", fill=(240, 240, 243), color=GREY, size=30)
|
||
else:
|
||
pill(img, CX, by, "v Принято", fill=(226, 247, 232), color=(40, 140, 80), size=32, scale=out_back(seg(t, ding, ding + 0.3)))
|
||
ripple(img, CX + 20, by + 6, t, press_t, PINK, 100)
|
||
# the cursor: to the button, a press, away
|
||
k = in_out(seg(t, a + 0.3, press_t - 0.1))
|
||
away = in_out(seg(t, press_t + 0.3, drop))
|
||
cx = lerp(lerp(CX + 50, CX + 26, k), CX + (380 if VERT else 520), away)
|
||
cy = lerp(lerp(CY + 26, by + 10, k), by + 220, away) + down * (H * 0.75)
|
||
put_c(img, cursor_sprite(), cx + 10, cy + 16, 1.0 - 0.08 * clamp(1 - abs(t - press_t) / 0.1), 1 - seg(t, drop - 0.2, drop + 0.2))
|
||
# the kitten
|
||
pop_t = ding + 0.9
|
||
if t >= pop_t:
|
||
leave = in_out(seg(t, S[4] + 0.35, S[4] + 0.75))
|
||
k = out_back(seg(t, pop_t, pop_t + 0.5), 2.0)
|
||
put_pet(img, t, "cat", "cub", lerp(CX, CX - (0 if VERT else 470), leave), CY - 20 + (1 - k) * 80, 520 * k * lerp(1, 0.6, leave), 1 - seg(t, S[4] + 0.6, S[4] + 0.75))
|
||
burst(img, CX, CY - 20, t, pop_t + 0.05, seed=7, n=44, power=620, life=1.3)
|
||
text(img, (CX, CY + 300), "Серийчик стал зверем", 54, "bold", INK, "mm", alpha=seg(t, pop_t + 0.35, pop_t + 0.7) * (1 - seg(t, S[4] + 0.1, S[4] + 0.4)))
|
||
|
||
|
||
def tile(kind: str, t: float, size: int) -> Image.Image:
|
||
pad = 80
|
||
layer = Image.new("RGBA", (size + 2 * pad, size + 2 * pad), (0, 0, 0, 0))
|
||
layer.alpha_composite(card(size, size, size // 7, PASTEL[kind], blur=40, dy=18, alpha=50), (pad - 80, pad - 80))
|
||
p = pet(t, kind).resize((int(size * 0.92), int(size * 0.92)), Image.Resampling.BICUBIC)
|
||
layer.alpha_composite(p, (pad + (size - p.width) // 2, pad + (size - p.height) // 2 + size // 30))
|
||
return layer
|
||
|
||
|
||
def scene_kinds(img, t):
|
||
"""Three tiles glide in (kitten, puppy, lion cub), fan out, then gather and turn into one kitten with a mew."""
|
||
a, fan, gather = S[4] + 0.45, S[6], S[7]
|
||
if t < a or t > S[8] + 0.2:
|
||
return
|
||
kinds = ("cat", "dog", "lion")
|
||
if t < gather + 0.3:
|
||
size = 300 if VERT else 400
|
||
wide, close = (335, 215) if VERT else (470, 300)
|
||
g = in_out(seg(t, gather - 0.3, gather))
|
||
f = in_out(seg(t, fan, fan + 0.5)) * (1 - g)
|
||
squash = 1 - 0.5 * seg(t, gather, gather + 0.3)
|
||
for i in (0, 2, 1):
|
||
come = out_cubic(seg(t, a + 0.25 + i * 0.22, a + 0.9 + i * 0.22))
|
||
bump = 1 + 0.07 * clamp(1 - abs(t - S[5]) / 0.18)
|
||
x = CX + (i - 1) * lerp(wide, close, f) * (1 - g) + (1 - come) * 1500 - (t - a) * (0 if VERT else 6) * (1 - f) * (1 - g)
|
||
y = CY - 30 + abs(i - 1) * 50 * f
|
||
angle = -(i - 1) * 9 * f
|
||
alpha = 1 - seg(t, gather + 0.15, gather + 0.3) if i == 0 else 1 - seg(t, gather - 0.05, gather + 0.1)
|
||
put_c(img, tile(kinds[i], t, size), x, y, bump * squash * lerp(1.0, 1.08 if i == 1 else 1.0, f), alpha * clamp(come * 3), angle)
|
||
label = seg(t, a + 0.7 + i * 0.22, a + 1.0 + i * 0.22) * (1 - seg(t, fan - 0.2, fan + 0.1))
|
||
text(img, (x, CY + (180 if VERT else 230)), NAMES[kinds[i]], 34 if VERT else 40, "semi", INK, "mm", alpha=label)
|
||
head = seg(t, S[5], S[5] + 0.35) * (1 - seg(t, gather - 0.3, gather))
|
||
text(img, (CX, CY - (300 if VERT else 360)), "Машут хвостом, дёргают ушами, моргают", 40 if VERT else 44, "semi", GREY, "mm", alpha=head)
|
||
if t >= gather + 0.25:
|
||
k = out_back(seg(t, gather + 0.25, gather + 0.75), 2.2)
|
||
put_pet(img, t, "cat", "cub", CX, CY - 10 + (1 - k) * 60, 560 * k)
|
||
burst(img, CX, CY - 10, t, gather + 0.3, seed=9, n=46, power=660, life=1.3)
|
||
|
||
|
||
STAGES = [("cub", 0, "Малыш"), ("teen", 7, "Подросток"), ("adult", 30, "Взрослый"), ("elder", 100, "Старший")]
|
||
|
||
|
||
def scene_grow(img, t):
|
||
"""The kitten grows with the days of the streak, goes grey when the streak is about to burn out, lights up again."""
|
||
a = S[8] + 0.2
|
||
if t < a or t > S[12] - 0.05:
|
||
return
|
||
marks = [a, S[8] + 1.0, S[9], S[10]]
|
||
index = max(i for i in range(4) if t >= marks[i])
|
||
stage, days, name = STAGES[index]
|
||
since = t - marks[index]
|
||
cold_t, warm_t = S[10] + 1.1, S[11]
|
||
cold = cold_t <= t < warm_t
|
||
leave = seg(t, S[12] - 0.4, S[12] - 0.05)
|
||
zoom = lerp(1.0, 1.16, in_out(seg(t, S[8], S[8] + 0.9)))
|
||
pop = 1 + 0.16 * clamp(1 - since / 0.25) if index else 1.0
|
||
pop *= 1 + 0.1 * clamp(1 - abs(t - warm_t - 0.08) / 0.2)
|
||
cx, cyc = (CX, CY - 330) if VERT else (CX - 330, CY + 10)
|
||
put_pet(img, t, "cat", stage, cx, cyc, 600 * zoom * pop * (1 - 0.3 * leave), 1 - leave, sad=cold)
|
||
for i in (1, 2, 3):
|
||
burst(img, cx, cyc, t, marks[i], seed=20 + i, n=26, power=480, life=0.9)
|
||
burst(img, cx, cyc, t, warm_t + 0.02, seed=31, n=60, power=760, life=1.4)
|
||
# the right side: the days, the name of the age, four dots
|
||
show = seg(t, a + 0.3, a + 0.7) * (1 - leave)
|
||
rx, ry = (CX, CY + 330) if VERT else (CX + 380, CY)
|
||
if index and since < 0.5: # the number runs up to the new age
|
||
days = int(lerp(STAGES[index - 1][1], days, out_cubic(since / 0.5)))
|
||
number = "%d" % days
|
||
text(img, (rx, ry - 120), number, 230, "black", (190, 190, 198) if cold else INK, "mm", alpha=show)
|
||
text(img, (rx, ry + 30), "дней серии" if days != 1 else "день серии", 44, "semi", GREY, "mm", alpha=show)
|
||
for i in range(4):
|
||
on = i <= index
|
||
put_c(img, disc(26, (190, 190, 198) if cold and on else PINK if on else (228, 228, 234)), rx - 75 + i * 50, ry + 110,
|
||
(1 + 0.5 * clamp(1 - since / 0.25)) if i == index else 1.0, show)
|
||
if cold:
|
||
pill(img, rx, ry + 210, "Серия вот-вот сгорит", fill=(236, 236, 240), color=(110, 110, 120), size=34,
|
||
scale=out_back(seg(t, cold_t, cold_t + 0.3)), alpha=show)
|
||
elif t >= warm_t:
|
||
pill(img, rx, ry + 210, "v Серия продлена", fill=(226, 247, 232), color=(40, 140, 80), size=34,
|
||
scale=out_back(seg(t, warm_t, warm_t + 0.3)), alpha=show)
|
||
else:
|
||
pill(img, rx, ry + 210, name, fill=INK, size=34, scale=0.85 + 0.15 * out_back(clamp(since / 0.3)), alpha=show)
|
||
|
||
|
||
def scene_chat(img, t):
|
||
"""An invented chat with no names and no words: the animal sits in it and the cursor carries it to the other side. Three big lines."""
|
||
a, b = S[12], S[14]
|
||
if t < a - 0.1 or t > b + 0.2:
|
||
return
|
||
step = (b - a) / 3
|
||
come = out_cubic(seg(t, a - 0.1, a + 0.5))
|
||
gone = in_out(seg(t, b - 0.25, b + 0.15))
|
||
w, h = 560, 860
|
||
px = CX if VERT else CX - 440
|
||
py = (CY - 290 if VERT else CY) + (1 - come) * (1500 if VERT else 900) + gone * (-1700 if VERT else 1000)
|
||
put_c(img, card(w, h, 60, (255, 255, 255), blur=44, dy=22, alpha=56), px, py)
|
||
left, top = px - w // 2, py - h // 2
|
||
put(img, disc(72, (222, 232, 255)), left + 40, top + 36)
|
||
put(img, rr(170, 20, 10, (226, 226, 232)), left + 130, top + 50)
|
||
pill(img, left + w - 100, top + 72, "30 дней", fill=(255, 236, 214), color=(220, 110, 30), size=24)
|
||
put(img, rr(w - 80, 2, 1, (238, 238, 242)), left + 40, top + 130)
|
||
rows = [(0, 300), (0, 220), (1, 260), (0, 340), (1, 180)]
|
||
for i, (mine, bw) in enumerate(rows):
|
||
k = out_back(seg(t, a + 0.25 + i * 0.09, a + 0.6 + i * 0.09), 1.2)
|
||
if k <= 0:
|
||
continue
|
||
fill = VIOLET if mine else (240, 240, 243)
|
||
bx = left + w - 40 - bw if mine else left + 40
|
||
by = top + 160 + i * 86
|
||
bubble = rr(bw, 62, 28, fill)
|
||
put_c(img, bubble, bx + bw / 2, by + 31, k, clamp(k))
|
||
if k > 0.9:
|
||
put(img, rr(bw - 70, 12, 6, (255, 255, 255) if mine else (206, 206, 214)), bx + 35, by + 25, 0.9 if mine else 1.0)
|
||
# the animal: sits on the left, is taken on the second line and carried to the right
|
||
take, drop = a + step, a + step + 0.9
|
||
k = in_out(seg(t, take, drop))
|
||
ax = lerp(left + 120, left + w - 120, k)
|
||
ay = top + h - 135 - math.sin(k * math.pi) * 90
|
||
put_pet(img, t, "cat", "adult", ax, ay, 210 * out_back(seg(t, a + 0.5, a + 0.9)) * (1 + 0.08 * math.sin(k * math.pi)), angle=-10 * math.sin(k * math.pi))
|
||
ck = in_out(seg(t, take - 0.7, take))
|
||
away = in_out(seg(t, drop + 0.1, drop + 0.6))
|
||
cx = lerp(lerp(left + w + 200, left + 130, ck), left + w + 260, away) if k in (0, 1) else ax + 10
|
||
cy = lerp(lerp(top + h + 60, top + h - 130, ck), top + h + 80, away) if k in (0, 1) else ay + 20
|
||
if k == 1 and away == 0:
|
||
cx, cy = ax + 10, ay + 20
|
||
put_c(img, cursor_sprite(), cx + 10, cy + 16, 1.0, seg(t, take - 0.7, take - 0.5) * (1 - seg(t, drop + 0.4, drop + 0.6)) * (1 - gone))
|
||
# the three lines
|
||
lines = ["Живёт в вашем чате", "Его можно таскать", "Растёт вместе с серией"]
|
||
for i, line in enumerate(lines):
|
||
t0 = a + i * step
|
||
k = out_cubic(seg(t, t0, t0 + 0.35))
|
||
fade = (1 - gone) * (1.0 if t < t0 + step or i == 2 else 0.28)
|
||
if VERT:
|
||
text(img, (CX, CY + 300 + i * 130 + (1 - k) * 40), line, 72, "bold", INK, "mm", alpha=k * fade)
|
||
else:
|
||
text(img, (CX - 60, CY - 150 + i * 150 + (1 - k) * 40), line, 84, "bold", INK, "lm", alpha=k * fade)
|
||
|
||
|
||
def scene_title(img, t):
|
||
"""The title: LihonT 3 in black, LUNA in candy letters; then the logo."""
|
||
a = S[14] + 0.1
|
||
if t < a:
|
||
return
|
||
logo_t = S[15]
|
||
k1 = 1 - seg(t, logo_t - 0.1, logo_t + 0.3)
|
||
if VERT:
|
||
text(img, (CX, CY - 330), "LihonT 3", 170, "semi", INK, "mm", alpha=out_cubic(seg(t, a, a + 0.4)) * k1)
|
||
V.candy_text(img, CX, CY - 130, "LUNA", 200, t, a + 0.25, 0.09, alpha=k1)
|
||
text(img, (CX, CY + 60), "pre-alpha", 46, "semi", GREY, "mm", alpha=out_cubic(seg(t, a + 0.9, a + 1.3)) * k1)
|
||
text(img, (CX, CY + 125), "у Серийчика появились звери", 46, "reg", GREY, "mm", alpha=out_cubic(seg(t, a + 1.0, a + 1.4)) * k1)
|
||
row_y, gap, side, logo, logo_size, cap_y = CY + 380, 290, 270, (CX, CY - 130), 560, CY + 300
|
||
else:
|
||
text(img, (680, 450), "LihonT 3", 150, "semi", INK, "mm", alpha=out_cubic(seg(t, a, a + 0.4)) * k1)
|
||
V.candy_text(img, 1270, 450, "LUNA", 150, t, a + 0.25, 0.09, alpha=k1)
|
||
text(img, (960, 620), "pre-alpha · у Серийчика появились звери", 40, "reg", GREY, "mm", alpha=out_cubic(seg(t, a + 0.9, a + 1.3)) * k1)
|
||
row_y, gap, side, logo, logo_size, cap_y = 830, 230, 210, (960, 470), 420, 770
|
||
for i, kind in enumerate(("cat", "dog", "lion")):
|
||
k = out_back(seg(t, a + 0.7 + i * 0.12, a + 1.1 + i * 0.12), 2.0)
|
||
put_pet(img, t, kind, "cub", CX + (i - 1) * gap, row_y + (1 - k) * 40, side * k, k1)
|
||
if t >= logo_t - 0.05:
|
||
flower = Image.open(V.ROOT / "src" / "brand" / "logo_note_flower_gold_1024.png").convert("RGBA")
|
||
k = out_back(seg(t, logo_t, logo_t + 0.6), 1.5)
|
||
put_c(img, flower.resize((logo_size, logo_size), Image.Resampling.LANCZOS), logo[0], logo[1], k, clamp(k * 1.5))
|
||
text(img, (CX, cap_y), "lihont.space · t.me/lihont", 38, "semi", GREY, "mm", alpha=seg(t, logo_t + 0.5, logo_t + 0.9))
|
||
burst(img, logo[0], logo[1], t, logo_t + 0.1, seed=11, n=50, power=700, life=1.4)
|
||
|
||
|
||
# ---------------------------------------------------------------- the whole picture
|
||
|
||
def frame_at(t: float) -> Image.Image:
|
||
img = Image.new("RGBA", (W, H), (255, 255, 255, 255))
|
||
for scene in (scene_link, scene_gift, scene_kinds, scene_grow, scene_chat, scene_title):
|
||
scene(img, t)
|
||
fade_in = clamp(t / 0.25)
|
||
if fade_in < 1:
|
||
img.alpha_composite(Image.new("RGBA", (W, H), (255, 255, 255, int(255 * (1 - fade_in)))))
|
||
return img
|
||
|
||
|
||
def render_frame(index: int) -> bytes:
|
||
return frame_at(index / FPS).convert("RGB").tobytes()
|
||
|
||
|
||
def _init(song: str, vertical: bool = False) -> None:
|
||
global S
|
||
V.configure(song)
|
||
set_format(vertical)
|
||
S = V.S
|
||
|
||
|
||
def main() -> None:
|
||
parser = argparse.ArgumentParser()
|
||
parser.add_argument("--song", default="store")
|
||
parser.add_argument("--still", type=float, nargs="*")
|
||
parser.add_argument("--sheet", action="store_true")
|
||
parser.add_argument("--vertical", action="store_true", help="9:16 (1080x1920)")
|
||
parser.add_argument("--jobs", type=int, default=6)
|
||
args = parser.parse_args()
|
||
_init(args.song, args.vertical)
|
||
tag = "_9x16" if args.vertical else ""
|
||
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
||
prepare()
|
||
if args.still:
|
||
for t in args.still:
|
||
path = OUT_DIR / ("still%s_%05.2f.png" % (tag, t))
|
||
frame_at(t).convert("RGB").save(path)
|
||
print(path)
|
||
return
|
||
if args.sheet:
|
||
count, cols = 36, 6
|
||
tw, th = (216, 384) if args.vertical else (480, 270)
|
||
cols = 9 if args.vertical else 6
|
||
out = Image.new("RGB", (cols * (tw + 4), (count // cols) * (th + 4)), (200, 200, 205))
|
||
for i in range(count):
|
||
thumb = frame_at(V.DURATION * (i + 0.5) / count).convert("RGB").resize((tw, th), Image.Resampling.LANCZOS)
|
||
out.paste(thumb, ((i % cols) * (tw + 4) + 2, (i // cols) * (th + 4) + 2))
|
||
out.save(OUT_DIR / ("sheet%s.png" % tag))
|
||
print(OUT_DIR / ("sheet%s.png" % tag))
|
||
return
|
||
out = OUT_DIR / ("lihont3_pets%s.mp4" % tag)
|
||
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(V.SONG), "-c:v", "libx264", "-preset", "medium", "-crf", "17", "-pix_fmt", "yuv420p",
|
||
"-af", "afade=t=out:st=%.2f:d=0.6" % (V.DURATION - 0.6), "-c:a", "aac", "-b:a", "192k", "-t", "%.2f" % V.DURATION, str(out)]
|
||
proc = subprocess.Popen(command, stdin=subprocess.PIPE)
|
||
with Pool(args.jobs, initializer=_init, initargs=(args.song, args.vertical)) as pool:
|
||
for n, data in enumerate(pool.imap(render_frame, range(V.FRAMES), chunksize=4)):
|
||
proc.stdin.write(data)
|
||
if n % 120 == 0:
|
||
print("frame %d/%d" % (n, V.FRAMES), flush=True)
|
||
proc.stdin.close()
|
||
proc.wait()
|
||
print("done:", out)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|