Lock for the whole app, every chat or chosen chats, opened by the phone's own fingerprint, face or lock-screen code. A journal of entries (time, result, wrong fingers, chats opened) with optional front-camera pictures kept in a private folder, and a clear-all button. Also: the mascot and the promo scripts for this release. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
168 lines
8.7 KiB
Python
168 lines
8.7 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 mascot(sad=False, frame=0, happy=False, mouth=0.0, size=None):
|
|
"""One picture of the cat. `mouth` 0..1 opens the mouth (it mews: the eyes close then); `size` is the side in pixels."""
|
|
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:
|
|
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)
|
|
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)
|
|
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()
|