Files
LihonT/scripts/make_plugin_howto.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

179 lines
10 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
"""Draws src/brand/plugin_howto.svg: a light looping animation "your own plugin in four steps" (SMIL, no scripts).
python scripts/make_plugin_howto.py [out.svg]
"""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
OUT = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "src" / "brand" / "plugin_howto.svg"
W, H = 800, 450
SCENE = 4.0 # seconds per step
STEPS = 4
TOTAL = SCENE * STEPS
BG, CARD, EDGE, TEXT, DIM = "#1E1B16", "#2B2620", "#4E4840", "#EAE1D9", "#9A9084"
GOLD, ORANGE, GREEN = "#F0BF6D", "#FFB27A", "#9ED69A"
MONO = "ui-monospace, Consolas, 'Courier New', monospace"
SANS = "system-ui, 'Segoe UI', Roboto, sans-serif"
def frac(t: float) -> str:
return "%.4f" % min(max(t / TOTAL, 0.0), 1.0)
def window(i: int):
"""Opacity of scene i: fades in, stays, fades out, then sleeps until the loop restarts."""
a, b = i * SCENE, (i + 1) * SCENE
times = [0, a, a + 0.4, b - 0.4, b, TOTAL]
values = [0, 0, 1, 1, 0, 0]
pairs = []
for t, v in zip(times, values):
pairs.append((frac(t), v))
# key times must not decrease; equal neighbours are fine
return ";".join(p[0] for p in pairs), ";".join(str(p[1]) for p in pairs)
def appear(start: float, duration: float = 0.01) -> str:
"""Opacity 0 until `start` seconds into the step, then 1 until the step ends (scene fade hides the rest)."""
return ('<animate attributeName="opacity" values="0;0;1;1" keyTimes="0;%s;%s;1" dur="%gs" repeatCount="indefinite"/>'
% (frac(start), frac(start + duration), TOTAL))
def type_line(x: float, y: float, width: float, start: float, seconds: float, content: str, fill: str, size: int = 17,
font: str = MONO, uid: str = "") -> str:
"""A line that is typed: a clip rectangle grows over it."""
cid = "c" + uid
return (
'<clipPath id="%s"><rect x="%g" y="%g" width="0" height="30">'
'<animate attributeName="width" values="0;0;%g;%g;0" keyTimes="0;%s;%s;%s;1" dur="%gs" repeatCount="indefinite"/>'
'</rect></clipPath>'
'<text x="%g" y="%g" font-family="%s" font-size="%d" fill="%s" clip-path="url(#%s)" xml:space="preserve">%s</text>'
% (cid, x - 2, y - 22, width, width, frac(start), frac(start + seconds), frac(TOTAL - 0.2), TOTAL,
x, y, font, size, fill, cid, content))
def scene(i: int, body: str) -> str:
kt, vals = window(i)
return ('<g opacity="0"><animate attributeName="opacity" values="%s" keyTimes="%s" dur="%gs" repeatCount="indefinite"/>%s</g>'
% (vals, kt, TOTAL, body))
def caption(text: str, sub: str) -> str:
return ('<text x="400" y="395" text-anchor="middle" font-family="%s" font-size="26" font-weight="600" fill="%s">%s</text>'
'<text x="400" y="423" text-anchor="middle" font-family="%s" font-size="16" fill="%s">%s</text>'
% (SANS, TEXT, text, SANS, DIM, sub))
def editor_scene() -> str:
s = SCENE * 0
body = ['<rect x="80" y="86" width="640" height="236" rx="18" fill="%s" stroke="%s" stroke-width="2"/>' % (CARD, EDGE)]
for k, color in enumerate(("#FF6B6B", GOLD, GREEN)):
body.append('<circle cx="%d" cy="108" r="6" fill="%s"/>' % (108 + 22 * k, color))
body.append('<text x="400" y="113" text-anchor="middle" font-family="%s" font-size="14" fill="%s">night.py</text>' % (SANS, DIM))
lines = [
(150, 'from lihont_ltp import *', 0.5, ORANGE),
(186, 'plugin = Plugin("Тихая ночь", author="Вася")', 1.2, TEXT),
(222, 'plugin.video(night &amp; hashtag("fyp"), hide)', 2.2, TEXT),
(258, 'plugin.save()', 3.0, GREEN),
]
for n, (y, text, start, fill) in enumerate(lines):
body.append(type_line(112, y + 14, 560, s + start, 0.7 if n != 2 else 0.8, text, fill, uid="a%d" % n))
body.append(caption("1. Напиши правило, как предложение", "Видео с #fyp ночью скрыть: три строки на Python"))
return scene(0, "".join(body))
def terminal_scene() -> str:
s = SCENE * 1
body = ['<rect x="80" y="86" width="640" height="236" rx="18" fill="#17140F" stroke="%s" stroke-width="2"/>' % EDGE]
body.append(type_line(110, 130, 400, s + 0.4, 0.8, "$ python night.py", TEXT, uid="b0"))
rows = [
(170, "Защитник: Обратите внимание", GOLD, 1.5),
(200, "• Скрывает видео из ленты по условиям правил", DIM, 1.9),
(230, "Плагин не может: читать сообщения и пароли, запускать код.", DIM, 2.3),
(272, "Готово: vasya.tihaya-noch.ltp", GREEN, 2.8),
]
for y, text, fill, start in rows:
body.append('<text x="110" y="%d" font-family="%s" font-size="16" fill="%s" opacity="0" xml:space="preserve">%s%s</text>'
% (y, MONO, fill, text, appear(s + start)))
# the finished file pops up
body.append('<g transform="translate(640 250)" opacity="0">%s'
'<rect x="-26" y="-34" width="52" height="68" rx="8" fill="%s"/><text x="0" y="8" text-anchor="middle" '
'font-family="%s" font-size="16" font-weight="700" fill="#2B2620">.ltp</text></g>'
% (appear(s + 3.0, 0.2), GOLD, SANS))
body.append(caption("2. Запусти: защитник покажет всё", "Что делает каждое правило и насколько ему можно доверять"))
return scene(1, "".join(body))
def phone_scene() -> str:
s = SCENE * 2
body = []
# laptop
body.append('<rect x="90" y="150" width="230" height="140" rx="12" fill="%s" stroke="%s" stroke-width="2"/>' % (CARD, EDGE))
body.append('<rect x="70" y="296" width="270" height="12" rx="6" fill="%s"/>' % EDGE)
body.append('<text x="205" y="212" text-anchor="middle" font-family="%s" font-size="15" fill="%s">ltp phone</text>' % (MONO, TEXT))
body.append('<text x="205" y="238" text-anchor="middle" font-family="%s" font-size="13" fill="%s">vasya.tihaya-noch.ltp</text>' % (MONO, GOLD))
# cable
body.append('<path d="M320 220 C 400 220 430 220 500 220" stroke="%s" stroke-width="4" fill="none" stroke-dasharray="6 6"/>' % EDGE)
# phone
body.append('<rect x="500" y="110" width="130" height="236" rx="22" fill="%s" stroke="%s" stroke-width="3"/>' % (CARD, EDGE))
body.append('<rect x="515" y="130" width="100" height="196" rx="10" fill="#17140F"/>')
body.append('<text x="565" y="236" text-anchor="middle" font-family="%s" font-size="13" fill="%s">Download/ltp</text>' % (SANS, DIM))
# the file travels along the cable, twice
body.append('<g><rect x="-14" y="-18" width="28" height="36" rx="5" fill="%s"/>'
'<animateMotion dur="%gs" repeatCount="indefinite" keyPoints="0;0;1;1" keyTimes="0;%s;%s;1" calcMode="linear" '
'path="M330 220 L 540 220"/></g>' % (GOLD, TOTAL, frac(s + 0.6), frac(s + 2.4)))
body.append(caption("3. Отправь на телефон по проводу", "Команда ltp phone кладёт файл в Download/ltp"))
return scene(2, "".join(body))
def install_scene() -> str:
s = SCENE * 3
body = ['<rect x="250" y="60" width="300" height="320" rx="30" fill="%s" stroke="%s" stroke-width="3"/>' % (CARD, EDGE)]
body.append('<rect x="272" y="150" width="256" height="150" rx="20" fill="#3A342C"/>')
body.append('<text x="288" y="182" font-family="%s" font-size="16" font-weight="700" fill="%s">Установить «Тихая ночь»?</text>' % (SANS, TEXT))
body.append('<text x="288" y="208" font-family="%s" font-size="12" fill="%s">Защитник: Обратите внимание</text>' % (SANS, GOLD))
body.append('<text x="288" y="228" font-family="%s" font-size="12" fill="%s">Права: скрывать видео по правилам</text>' % (SANS, DIM))
body.append('<text x="410" y="284" font-family="%s" font-size="14" fill="%s">Отмена</text>' % (SANS, DIM))
body.append('<g><rect x="468" y="266" width="52" height="26" rx="13" fill="%s"/>'
'<text x="494" y="284" text-anchor="middle" font-family="%s" font-size="13" font-weight="700" fill="#2B2620">Ставь</text>'
'<animate attributeName="opacity" values="1;1;0.55;1;1" keyTimes="0;%s;%s;%s;1" dur="%gs" repeatCount="indefinite"/></g>'
% (GOLD, SANS, frac(s + 1.5), frac(s + 1.8), frac(s + 2.1), TOTAL))
body.append('<g opacity="0">%s<rect x="276" y="330" width="248" height="34" rx="17" fill="%s"/>'
'<text x="400" y="352" text-anchor="middle" font-family="%s" font-size="14" font-weight="700" fill="#2B2620">Плагин включён ✓</text></g>'
% (appear(s + 2.4, 0.2), GREEN, SANS))
body.append(caption("4. Установи и включи", "Перед установкой видно права, правила и вердикт защитника"))
return scene(3, "".join(body))
def dots() -> str:
out = []
for i in range(STEPS):
a, b = i * SCENE, (i + 1) * SCENE
out.append('<circle cx="%g" cy="46" r="7" fill="%s">'
'<animate attributeName="fill" values="%s;%s;%s;%s;%s" keyTimes="0;%s;%s;%s;1" dur="%gs" repeatCount="indefinite"/>'
'</circle>' % (370 + 20 * i, EDGE, EDGE, EDGE, GOLD, EDGE, EDGE, frac(a), frac(a + 0.01), frac(b), TOTAL))
return "".join(out)
def build() -> str:
parts = [
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %d %d" width="%d" height="%d" role="img" '
'aria-label="Как создать свой плагин для LihonT за четыре шага">' % (W, H, W, H),
'<rect width="%d" height="%d" rx="28" fill="%s"/>' % (W, H, BG),
'<text x="400" y="52" text-anchor="middle" font-family="%s" font-size="0"> </text>' % SANS,
'<text x="40" y="52" font-family="%s" font-size="22" font-weight="700" fill="%s">Свой плагин для LihonT</text>' % (SANS, GOLD),
dots(),
editor_scene(), terminal_scene(), phone_scene(), install_scene(),
'</svg>',
]
return "\n".join(parts)
if __name__ == "__main__":
OUT.parent.mkdir(parents=True, exist_ok=True)
OUT.write_text(build(), encoding="utf-8", newline="\n")
print("%s %d bytes" % (OUT, OUT.stat().st_size))