The "Как сайт" look by default, also in TikTok's settings and all their sub-pages, where every item is its own rounded row. The bottom bar floats as an island, 9:16 videos reach under it, the seek bar is lifted, thicker and on by default, the comment input is an island too, and "only sound" downloads are saved as audio. The LihonT agent: a chat that makes cards and slides for a photo post, looks things up on the web, signs in with Telegram and has a daily limit on the server. Also the нейронка.рус landing page and the 3D-phone promo scripts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
224 lines
12 KiB
Python
224 lines
12 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
The mascot of LihonT: a tricolour cat (white, brown and black, like the user's own cat) with a collar and, on the collar, a round
|
|
tag with the gold flower-and-note of the logo. Drawn with the same hands as the Серийчик animals (scripts/make_pet_designs.py): round,
|
|
thick outline, a tail that wags, ears that twitch, a blink.
|
|
|
|
py -X utf8 -B scripts/make_mascot.py # work/mascot/*.png, mascot_anim.gif and sheet.png
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageChops, ImageDraw
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import make_pet_designs as D # noqa: E402
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUT = ROOT / "work" / "mascot"
|
|
SIZE = 1024
|
|
WHITE_FUR = (255, 252, 246)
|
|
BROWN = (178, 108, 58)
|
|
BLACK = (54, 46, 52)
|
|
EAR_IN = (255, 160, 170)
|
|
COLLAR = (255, 99, 150) # the pink of the site's candy letters
|
|
COLLAR_DARK = (222, 52, 112)
|
|
GOLD = (238, 190, 107)
|
|
GOLD_DARK = (214, 150, 52)
|
|
NOTE = (92, 28, 40)
|
|
|
|
|
|
def patch(cv, region, shapes):
|
|
"""Draws the (cx, cy, rx, ry, colour) ellipses of `shapes` and keeps only what lies inside the ellipse `region`: a patch of colour on the coat."""
|
|
size = cv.img.size
|
|
layer = Image.new("RGBA", size, (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(layer)
|
|
for cx, cy, rx, ry, color in shapes:
|
|
x, y = cv.t(cx, cy)
|
|
a, b = rx * D.W * cv.K, ry * D.W * cv.K
|
|
d.ellipse([x - a, y - b, x + a, y + b], fill=tuple(cv.c(color)) + (255,))
|
|
mask = Image.new("L", size, 0)
|
|
x, y = cv.t(region[0], region[1])
|
|
a, b = region[2] * D.W * cv.K, region[3] * D.W * cv.K
|
|
ImageDraw.Draw(mask).ellipse([x - a, y - b, x + a, y + b], fill=255)
|
|
layer.putalpha(ImageChops.multiply(layer.getchannel("A"), mask))
|
|
cv.img.alpha_composite(layer)
|
|
cv.d = ImageDraw.Draw(cv.img)
|
|
|
|
|
|
def collar(cv, cx, head_cy, head):
|
|
"""The collar round the neck; drawn before the head so the chin lies over it."""
|
|
cv.ell(cx, head_cy + head * 0.86, head * 0.84, head * 0.2, COLLAR)
|
|
cv.arc(cx, head_cy + head * 0.86, head * 0.78, head * 0.15, 20, 160, 0.008, tuple(cv.c(COLLAR_DARK)))
|
|
|
|
|
|
def tag(cv, cx, cy, r):
|
|
"""The round tag on the collar: the logo's gold flower with the dark note on it."""
|
|
petals = [(cx + math.cos(k * math.tau / 9) * r * 0.62, cy + math.sin(k * math.tau / 9) * r * 0.62, r * 0.42) for k in range(9)]
|
|
for outline in (True, False):
|
|
for x, y, rr in petals + [(cx, cy, r * 0.8)]:
|
|
(px, py), q = cv.t(x, y), rr * D.W * cv.K + (0.011 * D.W if outline else 0)
|
|
cv.d.ellipse([px - q, py - q, px + q, py + q], fill=D.INK if outline else tuple(cv.c(GOLD)))
|
|
cv.ell(cx, cy, r * 0.62, r * 0.62, GOLD_DARK, outline=False)
|
|
cv.ell(cx, cy, r * 0.56, r * 0.56, GOLD, outline=False)
|
|
note = tuple(cv.c(NOTE))
|
|
cv.ell(cx - r * 0.16, cy + r * 0.26, r * 0.22, r * 0.16, NOTE, outline=False)
|
|
cv.line([(cx + r * 0.03, cy + r * 0.2), (cx + r * 0.03, cy - r * 0.34)], r * 0.1, note)
|
|
cv.poly([(cx + r * 0.0, cy - r * 0.36), (cx + r * 0.3, cy - r * 0.18), (cx + r * 0.3, cy - r * 0.02), (cx + r * 0.0, cy - r * 0.2)], NOTE, outline=False)
|
|
|
|
|
|
def heart(cv, x, y, r, color):
|
|
"""A heart made of two circles and a point, for the heart eyes."""
|
|
cv.ell(x - r * 0.5, y - r * 0.25, r * 0.55, r * 0.55, color, outline=False)
|
|
cv.ell(x + r * 0.5, y - r * 0.25, r * 0.55, r * 0.55, color, outline=False)
|
|
cv.poly([(x - r * 1.03, y - r * 0.05), (x + r * 1.03, y - r * 0.05), (x, y + r * 1.0)], color, outline=False)
|
|
|
|
|
|
def mascot(sad=False, frame=0, happy=False, mouth=0.0, size=None, look=None, prop=None):
|
|
"""One picture of the cat. `mouth` 0..1 opens the mouth (it mews: the eyes close then); `size` is the side in pixels.
|
|
|
|
`look` changes the face (heart, angry, shock, sad, cool, wink, sleep) and `prop` the paws (wave, thumb): for the stickers."""
|
|
size = size or SIZE
|
|
tail_a, ear_l, ear_r, blink, bob = D.motion(frame)
|
|
if sad:
|
|
tail_a, ear_l, ear_r = tail_a * 0.3, ear_l * 0.5, ear_r * 0.5
|
|
if happy or mouth > 0.4 or look == "sleep":
|
|
blink = 1.0
|
|
D.SIZE, D.W = size, size * D.S
|
|
cv = D.Canvas(sad)
|
|
head, body, _, height = D.LOOK["teen"]
|
|
head, body = head * 1.12, body * 1.12
|
|
cx, bottom = 0.5, 0.93
|
|
body_h = height + 0.10
|
|
body_cy = bottom - body_h * 0.5 - 0.02
|
|
head_cy = body_cy - body_h * 0.5 - head * 0.45 - bob
|
|
fx = cx + body
|
|
|
|
# the tail: brown with a black tip, out to the side and curling back at the end
|
|
q = [D.rot(p, (fx - 0.02, body_cy + body_h * 0.3), tail_a) for p in
|
|
[(fx - 0.02, body_cy + body_h * 0.3), (fx + 0.36, body_cy + body_h * 0.55), (fx + 0.42, body_cy - body_h * 0.75), (fx + 0.12, body_cy - body_h * 0.72)]]
|
|
D.tube(cv, q[0], q[1], q[2], q[3], 0.075, 0.045, BROWN, tip=BLACK)
|
|
|
|
# body: white, with a black and a brown patch
|
|
cv.ell(cx, body_cy, body, body_h * 0.5, WHITE_FUR)
|
|
patch(cv, (cx, body_cy, body, body_h * 0.5), [(cx - body * 0.75, body_cy - body_h * 0.35, body * 0.55, body_h * 0.42, BLACK),
|
|
(cx + body * 0.85, body_cy - body_h * 0.1, body * 0.5, body_h * 0.5, BROWN)])
|
|
cv.ell(cx, body_cy + body_h * 0.1, body * 0.5, body_h * 0.3, WHITE_FUR, outline=False)
|
|
for sign in (-1, 1):
|
|
cv.ell(cx + sign * body * 0.52, bottom - 0.035, 0.07, 0.045, BROWN if sign > 0 else WHITE_FUR)
|
|
cv.ell(cx + sign * body * 0.52, bottom - 0.02, 0.045, 0.02, WHITE_FUR, outline=False)
|
|
for sign in (-1, 1):
|
|
cv.ell(cx + sign * (body + 0.012), body_cy - body_h * 0.05, 0.035, 0.07, BLACK if sign < 0 else WHITE_FUR)
|
|
if prop in ("wave", "thumb"):
|
|
sway = 0.035 * math.sin(frame / 24 * math.tau * 2) if prop == "wave" else 0.0
|
|
end = (cx + head * (1.28 if prop == "wave" else 1.12) + sway, head_cy + head * (0.2 if prop == "wave" else 0.55))
|
|
D.tube(cv, (cx + body * 0.8, body_cy - body_h * 0.2), (cx + body * 1.5, body_cy), (end[0] + 0.03, end[1] + 0.1), end, 0.07, 0.06, WHITE_FUR)
|
|
cv.ell(end[0], end[1] - 0.01, 0.052, 0.062, WHITE_FUR)
|
|
if prop == "thumb":
|
|
cv.ell(end[0] + 0.005, end[1] - 0.075, 0.022, 0.045, WHITE_FUR)
|
|
else:
|
|
for k in (-1, 0, 1):
|
|
cv.line([(end[0] + k * 0.02, end[1] - 0.045), (end[0] + k * 0.02, end[1] - 0.012)], 0.006, BROWN)
|
|
collar(cv, cx, head_cy, head)
|
|
|
|
# ears: one black, one brown
|
|
for sign in (-1, 1):
|
|
base = (cx + sign * head * 0.55, head_cy - head * 0.5)
|
|
a = ear_l if sign < 0 else ear_r
|
|
outer = [D.rot(p, base, a) for p in [(cx + sign * head * 0.28, head_cy - head * 0.7), (cx + sign * head * 0.98, head_cy - head * 1.12),
|
|
(cx + sign * head * 0.92, head_cy - head * 0.2)]]
|
|
inner = [D.rot(p, base, a) for p in [(cx + sign * head * 0.42, head_cy - head * 0.68), (cx + sign * head * 0.84, head_cy - head * 0.92),
|
|
(cx + sign * head * 0.8, head_cy - head * 0.38)]]
|
|
cv.poly(outer, BLACK if sign < 0 else BROWN)
|
|
cv.poly(inner, EAR_IN, outline=False)
|
|
|
|
# head: white, a black patch over the left ear side and a brown one over the right, a white blaze between them
|
|
cv.ell(cx, head_cy, head * 1.05, head * 0.92, WHITE_FUR)
|
|
patch(cv, (cx, head_cy, head * 1.05, head * 0.92), [(cx - head * 0.78, head_cy - head * 0.52, head * 0.5, head * 0.46, BLACK),
|
|
(cx + head * 0.82, head_cy - head * 0.42, head * 0.46, head * 0.52, BROWN),
|
|
(cx + head * 0.95, head_cy + head * 0.12, head * 0.2, head * 0.2, BLACK)])
|
|
cv.ell(cx, head_cy + head * 0.32, head * 0.55, head * 0.4, WHITE_FUR, outline=False)
|
|
D.face(cv, "cat", cx, head_cy + head * 0.02, head, sad, "cub", blink)
|
|
if mouth > 0: # an open mouth over the smile: the muzzle is repainted, then a dark mouth with a tongue
|
|
my = head_cy + head * 0.32
|
|
cv.ell(cx, my + head * 0.02, head * 0.2, head * 0.1, WHITE_FUR, outline=False)
|
|
cv.ell(cx, my + head * 0.07, head * 0.085 * (0.6 + 0.7 * mouth), head * (0.035 + 0.1 * mouth), (96, 34, 52), width=0.007)
|
|
cv.ell(cx, my + head * (0.1 + 0.05 * mouth), head * 0.05 * (0.6 + 0.7 * mouth), head * (0.018 + 0.03 * mouth), (255, 120, 140), outline=False)
|
|
if look and look != "sleep":
|
|
spread = head * 0.42
|
|
mouth_y = head_cy + head * 0.32
|
|
for sign in (-1, 1): # the eyes are wiped, new ones are drawn
|
|
cv.ell(cx + sign * spread, head_cy, head * 0.17, head * 0.15, WHITE_FUR, outline=False)
|
|
if look == "heart":
|
|
for sign in (-1, 1):
|
|
heart(cv, cx + sign * spread, head_cy, 0.05, (255, 70, 120))
|
|
elif look == "cool":
|
|
for sign in (-1, 1):
|
|
cv.ell(cx + sign * spread, head_cy, 0.07, 0.05, (28, 28, 36))
|
|
cv.line([(cx + sign * spread - 0.04, head_cy - 0.02), (cx + sign * spread - 0.01, head_cy - 0.035)], 0.008, (200, 200, 220))
|
|
cv.line([(cx - spread + 0.07, head_cy), (cx + spread - 0.07, head_cy)], 0.012, (28, 28, 36))
|
|
elif look == "shock":
|
|
for sign in (-1, 1):
|
|
cv.ell(cx + sign * spread, head_cy, 0.058, 0.064, (255, 255, 255))
|
|
cv.ell(cx + sign * spread, head_cy + 0.006, 0.014, 0.018, D.INK, outline=False)
|
|
cv.ell(cx, mouth_y + head * 0.08, 0.03, 0.042, (96, 34, 52), width=0.008)
|
|
else:
|
|
D.eyes(cv, cx, head_cy, spread, 0.04, False, 0.0)
|
|
if look == "wink":
|
|
cv.ell(cx + spread, head_cy, head * 0.17, head * 0.15, WHITE_FUR, outline=False)
|
|
cv.arc(cx + spread, head_cy + 0.01, 0.045, 0.034, 200, 340, 0.011)
|
|
cv.ell(cx + 0.03, mouth_y + head * 0.15, 0.024, 0.034, (255, 120, 140))
|
|
elif look == "angry":
|
|
for sign in (-1, 1):
|
|
cv.line([(cx + sign * (spread + 0.07), head_cy - 0.095), (cx + sign * (spread - 0.055), head_cy - 0.045)], 0.016, D.INK)
|
|
cv.ell(cx, mouth_y + head * 0.02, head * 0.2, head * 0.1, WHITE_FUR, outline=False)
|
|
cv.arc(cx - 0.02, mouth_y + head * 0.17, 0.028, 0.026, 200, 340, 0.011)
|
|
cv.arc(cx + 0.02, mouth_y + head * 0.17, 0.028, 0.026, 200, 340, 0.011)
|
|
elif look == "sad":
|
|
for sign in (-1, 1):
|
|
cv.line([(cx + sign * (spread + 0.06), head_cy - 0.05), (cx + sign * (spread - 0.05), head_cy - 0.095)], 0.014, D.INK)
|
|
cv.ell(cx + spread + 0.035, head_cy + 0.085, 0.016, 0.028, (120, 190, 255))
|
|
cv.ell(cx, mouth_y + head * 0.02, head * 0.2, head * 0.1, WHITE_FUR, outline=False)
|
|
cv.arc(cx - 0.02, mouth_y + head * 0.17, 0.028, 0.026, 200, 340, 0.011)
|
|
cv.arc(cx + 0.02, mouth_y + head * 0.17, 0.028, 0.026, 200, 340, 0.011)
|
|
tag(cv, cx, head_cy + head * 1.03, head * 0.27)
|
|
return cv.img.resize((size, size), Image.LANCZOS)
|
|
|
|
|
|
def on(color, image):
|
|
base = Image.new("RGBA", image.size, color + (255,))
|
|
base.alpha_composite(image)
|
|
return base.convert("RGB")
|
|
|
|
|
|
def main() -> None:
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
glad, calm, grey = mascot(happy=True), mascot(frame=4), mascot(sad=True, frame=4)
|
|
glad.save(OUT / "mascot_happy.png")
|
|
calm.save(OUT / "mascot.png")
|
|
grey.save(OUT / "mascot_grey.png")
|
|
# the head with the collar and tag as a square picture for icons
|
|
face = calm.crop((140, 190, 900, 950)).resize((512, 512), Image.LANCZOS)
|
|
face.save(OUT / "mascot_icon_512.png")
|
|
face.resize((64, 64), Image.LANCZOS).save(OUT / "mascot_icon_64.png")
|
|
frames = [on((255, 255, 255), mascot(frame=f)).resize((384, 384), Image.LANCZOS).quantize(colors=96, method=Image.MEDIANCUT, dither=Image.Dither.NONE) for f in range(D.FRAMES)]
|
|
frames[0].save(OUT / "mascot_anim.gif", save_all=True, append_images=frames[1:], duration=83, loop=0, disposal=1)
|
|
sheet = Image.new("RGB", (3 * 520, 2 * 520 + 90), (255, 255, 255))
|
|
for i, image in enumerate((calm, glad, grey)):
|
|
sheet.paste(on((255, 255, 255), image).resize((500, 500), Image.LANCZOS), (i * 520 + 10, 10))
|
|
sheet.paste(on((20, 20, 24), image).resize((500, 500), Image.LANCZOS), (i * 520 + 10, 530))
|
|
icon = Image.new("RGB", (3 * 520, 90), (244, 244, 246))
|
|
for i, size in enumerate((256, 128, 64)):
|
|
icon.paste(on((244, 244, 246), face.resize((size, size), Image.LANCZOS)), (i * 520 + 20, 90 - min(size, 80) if size < 90 else 0))
|
|
sheet.save(OUT / "sheet.png")
|
|
print(OUT / "sheet.png")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|