Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(pets): idle acts - pets do something on their own now and then

rubenluetke10-beepa66db486a600
diff --git a/docs/pets.md b/docs/pets.md
index 4177d86079..c0c8e447ca 100644
--- a/docs/pets.md
+++ b/docs/pets.md
@@ -200,6 +200,16 @@ Two row conventions make the pet feel alive:
closed to widest. While a live output level is fresh (under 250 ms old),
the renderer picks the frame from that level, lightly smoothed, so the mouth
follows the real voice. Without a level the row swings back and forth.
+- **Idle acts.** A pet may ship little one-shot scenes it plays on its own
+ while nothing happens: the dragon spits fire, the cat chases a ball of
+ yarn. They live on a second sheet, declared next to the animations:
+ `"acts_sheet": "acts.png"` and `"acts": {"fire": {"row": 0, "frames": 8,
+ "fps": 9}, ...}` (1-24 character slugs, at most 12 acts, one row each,
+ always one-shot). The renderer (`ui/orb/pet_renderer.py`) starts one at
+ random 6-18 s into an idle stretch and then every 14-40 s, never the same
+ act twice in a row; any other state cancels it, and the overlay's frame
+ timer covers the wait, so idling costs nothing extra. A user upload is a
+ single sheet, so the store drops `acts` from an uploaded `pet.json`.
Rules the loader enforces (`jarvis/ui/pets/manifest.py`):
@@ -230,7 +240,6 @@ committed PNGs match the script). User-created pets live in
| `bolt` | Bolt | A battery: charges while thinking, sparks on success, runs flat asleep |
| `mochi` | Mochi | A jelly blob that wobbles while listening |
| `shelly` | Shelly | A snail: the shell spins while thinking, it withdraws to sleep |
-| `pip` | Pip | A baby: babbles while talking, cries on errors, naps under a blanket |
| `ember` | Ember | A baby dragon: smoke rings while thinking, a fire breath on success, a sooty cough on errors, naps in its eggshell |
## Adding a pet
diff --git a/jarvis/ui/pets/builtin/bolt/acts.png b/jarvis/ui/pets/builtin/bolt/acts.png
new file mode 100644
index 0000000000..65cf9d694a
Binary files /dev/null and b/jarvis/ui/pets/builtin/bolt/acts.png differ
diff --git a/jarvis/ui/pets/builtin/bolt/pet.json b/jarvis/ui/pets/builtin/bolt/pet.json
index a9923d4ccc..b5b87fbb6e 100644
--- a/jarvis/ui/pets/builtin/bolt/pet.json
+++ b/jarvis/ui/pets/builtin/bolt/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "power_surge": {
+ "row": 0,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "drain_flop": {
+ "row": 1,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "spark_juggle": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "robot_dance": {
+ "row": 3,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "self_check": {
+ "row": 4,
+ "frames": 8,
+ "fps": 7,
+ "loop": false
+ },
+ "static_hair": {
+ "row": 5,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/brew/acts.png b/jarvis/ui/pets/builtin/brew/acts.png
new file mode 100644
index 0000000000..f6c3d22f49
Binary files /dev/null and b/jarvis/ui/pets/builtin/brew/acts.png differ
diff --git a/jarvis/ui/pets/builtin/brew/pet.json b/jarvis/ui/pets/builtin/brew/pet.json
index 6993674a21..527b2732ba 100644
--- a/jarvis/ui/pets/builtin/brew/pet.json
+++ b/jarvis/ui/pets/builtin/brew/pet.json
@@ -68,5 +68,38 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "lid_flip": {
+ "row": 0,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "steam_heart": {
+ "row": 1,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "pour_self": {
+ "row": 2,
+ "frames": 8,
+ "fps": 7,
+ "loop": false
+ },
+ "whistle_tune": {
+ "row": 3,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "bubble_hiccup": {
+ "row": 4,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/ember/acts.png b/jarvis/ui/pets/builtin/ember/acts.png
new file mode 100644
index 0000000000..2bf1f8ed9f
Binary files /dev/null and b/jarvis/ui/pets/builtin/ember/acts.png differ
diff --git a/jarvis/ui/pets/builtin/ember/pet.json b/jarvis/ui/pets/builtin/ember/pet.json
index 2f1f4d2c76..e9a5ffc42e 100644
--- a/jarvis/ui/pets/builtin/ember/pet.json
+++ b/jarvis/ui/pets/builtin/ember/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "fire_burst": {
+ "row": 0,
+ "frames": 8,
+ "fps": 9,
+ "loop": false
+ },
+ "smoke_rings": {
+ "row": 1,
+ "frames": 8,
+ "fps": 7,
+ "loop": false
+ },
+ "wing_stretch": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "tail_chase": {
+ "row": 3,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "egg_peek": {
+ "row": 4,
+ "frames": 8,
+ "fps": 6,
+ "loop": false
+ },
+ "sneeze": {
+ "row": 5,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/gigi/acts.png b/jarvis/ui/pets/builtin/gigi/acts.png
new file mode 100644
index 0000000000..d1818bb7b2
Binary files /dev/null and b/jarvis/ui/pets/builtin/gigi/acts.png differ
diff --git a/jarvis/ui/pets/builtin/gigi/pet.json b/jarvis/ui/pets/builtin/gigi/pet.json
index 9608dd30fb..b503410744 100644
--- a/jarvis/ui/pets/builtin/gigi/pet.json
+++ b/jarvis/ui/pets/builtin/gigi/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "phase_out": {
+ "row": 0,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "glitch_dance": {
+ "row": 1,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "boo": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "coin_flip": {
+ "row": 3,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "juggle_bits": {
+ "row": 4,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "loading": {
+ "row": 5,
+ "frames": 8,
+ "fps": 7,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/miso/acts.png b/jarvis/ui/pets/builtin/miso/acts.png
new file mode 100644
index 0000000000..2ad7ae5349
Binary files /dev/null and b/jarvis/ui/pets/builtin/miso/acts.png differ
diff --git a/jarvis/ui/pets/builtin/miso/pet.json b/jarvis/ui/pets/builtin/miso/pet.json
index 3293f4047b..f8095f3fb1 100644
--- a/jarvis/ui/pets/builtin/miso/pet.json
+++ b/jarvis/ui/pets/builtin/miso/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "yarn_play": {
+ "row": 0,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "groom": {
+ "row": 1,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "big_yawn": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "butterfly": {
+ "row": 3,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "loaf": {
+ "row": 4,
+ "frames": 8,
+ "fps": 6,
+ "loop": false
+ },
+ "knock_cup": {
+ "row": 5,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/mochi/acts.png b/jarvis/ui/pets/builtin/mochi/acts.png
new file mode 100644
index 0000000000..fb01890167
Binary files /dev/null and b/jarvis/ui/pets/builtin/mochi/acts.png differ
diff --git a/jarvis/ui/pets/builtin/mochi/pet.json b/jarvis/ui/pets/builtin/mochi/pet.json
index 12b35b13d6..88bab2707c 100644
--- a/jarvis/ui/pets/builtin/mochi/pet.json
+++ b/jarvis/ui/pets/builtin/mochi/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "big_bounce": {
+ "row": 0,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "split_merge": {
+ "row": 1,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "bubble_blow": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "shape_shift": {
+ "row": 3,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "melt_reform": {
+ "row": 4,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "wiggle_dance": {
+ "row": 5,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/builtin/pip/pet.json b/jarvis/ui/pets/builtin/pip/pet.json
deleted file mode 100644
index 85d989a392..0000000000
--- a/jarvis/ui/pets/builtin/pip/pet.json
+++ /dev/null
@@ -1,72 +0,0 @@
-{
- "format": "jarvis-pet/1",
- "id": "pip",
- "name": "Pip",
- "description": "A chubby baby with a pacifier who babbles when you talk and naps under a blanket.",
- "frame_size": 48,
- "sheet": "sheet.png",
- "animations": {
- "idle": {
- "row": 0,
- "frames": 8,
- "fps": 6,
- "loop": true,
- "accent_frames": 1,
- "accent_every": 3
- },
- "listening": {
- "row": 1,
- "frames": 6,
- "fps": 8,
- "loop": true
- },
- "thinking": {
- "row": 2,
- "frames": 8,
- "fps": 8,
- "loop": true
- },
- "talking": {
- "row": 3,
- "frames": 4,
- "fps": 10,
- "loop": true
- },
- "success": {
- "row": 4,
- "frames": 8,
- "fps": 10,
- "loop": false
- },
- "error": {
- "row": 5,
- "frames": 6,
- "fps": 9,
- "loop": false
- },
- "sleeping": {
- "row": 6,
- "frames": 6,
- "fps": 3,
- "loop": true
- },
- "working": {
- "row": 7,
- "frames": 8,
- "fps": 8,
- "loop": true
- },
- "searching": {
- "row": 8,
- "frames": 8,
- "fps": 8,
- "loop": true
- },
- "held": {
- "row": 9,
- "frames": 6,
- "fps": 10,
- "loop": true
- }
- }
-}
diff --git a/jarvis/ui/pets/builtin/pip/sheet.png b/jarvis/ui/pets/builtin/pip/sheet.png
deleted file mode 100644
index a82454bd2f..0000000000
Binary files a/jarvis/ui/pets/builtin/pip/sheet.png and /dev/null differ
diff --git a/jarvis/ui/pets/builtin/shelly/acts.png b/jarvis/ui/pets/builtin/shelly/acts.png
new file mode 100644
index 0000000000..cb7422c3de
Binary files /dev/null and b/jarvis/ui/pets/builtin/shelly/acts.png differ
diff --git a/jarvis/ui/pets/builtin/shelly/pet.json b/jarvis/ui/pets/builtin/shelly/pet.json
index f15576094b..9cf702bb3a 100644
--- a/jarvis/ui/pets/builtin/shelly/pet.json
+++ b/jarvis/ui/pets/builtin/shelly/pet.json
@@ -68,5 +68,44 @@
"fps": 10,
"loop": true
}
+ },
+ "acts_sheet": "acts.png",
+ "acts": {
+ "turbo": {
+ "row": 0,
+ "frames": 8,
+ "fps": 10,
+ "loop": false
+ },
+ "peek_hide": {
+ "row": 1,
+ "frames": 8,
+ "fps": 7,
+ "loop": false
+ },
+ "leaf_munch": {
+ "row": 2,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "shell_polish": {
+ "row": 3,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "rain_drop": {
+ "row": 4,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ },
+ "stalk_knot": {
+ "row": 5,
+ "frames": 8,
+ "fps": 8,
+ "loop": false
+ }
}
}
diff --git a/jarvis/ui/pets/loader.py b/jarvis/ui/pets/loader.py
index fc7d59d321..ba0cc4aaf6 100644
--- a/jarvis/ui/pets/loader.py
+++ b/jarvis/ui/pets/loader.py
@@ -14,7 +14,7 @@ from __future__ import annotations
import json
import logging
from collections.abc import Mapping
-from dataclasses import dataclass
+from dataclasses import dataclass, field
from pathlib import Path
from types import MappingProxyType
@@ -26,6 +26,7 @@ from jarvis.ui.pets.manifest import (
USER_ID_RE,
PetManifest,
PetManifestError,
+ check_act_cells,
check_cells,
check_sheet_size,
parse_manifest,
@@ -57,6 +58,10 @@ class PetPack:
manifest: PetManifest
directory: Path
frames: Mapping[str, tuple[Image.Image, ...]]
+ #: Decoded idle acts by name (empty when the pet has none).
+ acts: Mapping[str, tuple[Image.Image, ...]] = field(
+ default_factory=lambda: MappingProxyType({})
+ )
def builtin_root() -> Path:
@@ -115,20 +120,25 @@ def read_manifest(pet_dir: Path, *, builtin: bool) -> PetManifest:
raise PetManifestError(
f"pet.json names the id '{manifest.id}' but its folder is '{pet_dir.name}'."
)
- sheet_path = pet_dir / manifest.sheet
+ check_cells(manifest, *_probe_png(pet_dir / manifest.sheet, manifest.sheet))
+ if manifest.acts and manifest.acts_sheet is not None:
+ check_act_cells(manifest, *_probe_png(pet_dir / manifest.acts_sheet, manifest.acts_sheet))
+ return manifest
+
+
+def _probe_png(path: Path, name: str) -> tuple[int, int]:
+ """The ``(width, height)`` of a sheet, from its header only."""
try:
- if sheet_path.stat().st_size > MAX_SHEET_BYTES:
+ if path.stat().st_size > MAX_SHEET_BYTES:
raise PetManifestError("The sprite sheet is larger than 2 MB.")
- with Image.open(sheet_path) as probe:
+ with Image.open(path) as probe:
if probe.format != "PNG":
raise PetManifestError("The sprite sheet must be a PNG image.")
- width, height = probe.size
+ return probe.size
except FileNotFoundError as exc:
- raise PetManifestError(f"The sprite sheet '{manifest.sheet}' is missing.") from exc
+ raise PetManifestError(f"The sprite sheet '{name}' is missing.") from exc
except (OSError, SyntaxError, Image.DecompressionBombError) as exc:
raise PetManifestError("The sprite sheet could not be read as a PNG.") from exc
- check_cells(manifest, width, height)
- return manifest
def normalize_sheet(image: Image.Image) -> Image.Image:
@@ -154,14 +164,7 @@ def load_pet(pet_dir: Path, *, builtin: bool) -> PetPack:
"""Load and decode the pet in ``pet_dir``. Raises :class:`PetManifestError`."""
pet_dir = Path(pet_dir)
manifest = read_manifest(pet_dir, builtin=builtin)
- try:
- with Image.open(pet_dir / manifest.sheet) as raw:
- raw.load()
- sheet = normalize_sheet(raw)
- except (OSError, SyntaxError, Image.DecompressionBombError) as exc:
- raise PetManifestError("The sprite sheet could not be decoded.") from exc
- check_sheet_size(*sheet.size)
-
+ sheet = _decode(pet_dir / manifest.sheet)
size = manifest.frame_size
by_row: dict[str, tuple[Image.Image, ...]] = {}
frames: dict[str, tuple[Image.Image, ...]] = {}
@@ -174,7 +177,32 @@ def load_pet(pet_dir: Path, *, builtin: bool) -> PetPack:
for col in range(spec.frames)
)
frames[state] = by_row[resolved]
- return PetPack(manifest=manifest, directory=pet_dir, frames=MappingProxyType(frames))
+ acts: dict[str, tuple[Image.Image, ...]] = {}
+ if manifest.acts and manifest.acts_sheet is not None:
+ acts_sheet = _decode(pet_dir / manifest.acts_sheet)
+ for name, spec in manifest.acts.items():
+ top = spec.row * size
+ acts[name] = tuple(
+ acts_sheet.crop((col * size, top, (col + 1) * size, top + size))
+ for col in range(spec.frames)
+ )
+ return PetPack(
+ manifest=manifest,
+ directory=pet_dir,
+ frames=MappingProxyType(frames),
+ acts=MappingProxyType(acts),
+ )
+
+
+def _decode(path: Path) -> Image.Image:
+ try:
+ with Image.open(path) as raw:
+ raw.load()
+ sheet = normalize_sheet(raw)
+ except (OSError, SyntaxError, Image.DecompressionBombError) as exc:
+ raise PetManifestError("The sprite sheet could not be decoded.") from exc
+ check_sheet_size(*sheet.size)
+ return sheet
def load_default_pet() -> PetPack | None:
diff --git a/jarvis/ui/pets/manifest.py b/jarvis/ui/pets/manifest.py
index 8bf6d966f8..7852481779 100644
--- a/jarvis/ui/pets/manifest.py
+++ b/jarvis/ui/pets/manifest.py
@@ -15,7 +15,7 @@ from __future__ import annotations
import re
from collections.abc import Mapping
-from dataclasses import dataclass
+from dataclasses import dataclass, field
from types import MappingProxyType
from jarvis.ui.pets.states import (
@@ -37,6 +37,12 @@ USER_ID_RE = re.compile(r"^u[0-9a-f]{16}$")
#: A sheet is a plain PNG file name inside the pet folder, never a path.
_SHEET_NAME_RE = re.compile(r"^[A-Za-z0-9_-][A-Za-z0-9_.-]{0,63}\.png$")
+#: Name of an idle act: a short lowercase slug (``"fire"``, ``"yawn"``).
+ACT_NAME_RE = re.compile(r"^[a-z][a-z0-9_]{0,23}$")
+
+#: Most idle acts one pet may declare.
+MAX_ACTS = 12
+
MAX_NAME_CHARS = 40
MAX_DESCRIPTION_CHARS = 140
MIN_FPS = 1
@@ -89,6 +95,11 @@ class PetManifest:
sheet: str
animations: Mapping[str, AnimationSpec]
builtin: bool = False
+ #: Idle acts: short one-shot animations the pet plays now and then while
+ #: nothing happens (a yawn, a stretch, a puff of fire), each a row of
+ #: ``acts_sheet``. Optional; without them the pet just idles.
+ acts: Mapping[str, AnimationSpec] = field(default_factory=lambda: MappingProxyType({}))
+ acts_sheet: str | None = None
def spec_for(self, state: str) -> tuple[str, AnimationSpec]:
"""Return ``(resolved_state, spec)`` for ``state``.
@@ -111,7 +122,7 @@ class PetManifest:
def to_json(self) -> dict:
"""The ``pet.json`` shape (``builtin`` is not part of the file)."""
- return {
+ out = {
"format": PET_FORMAT,
"id": self.id,
"name": self.name,
@@ -124,6 +135,10 @@ class PetManifest:
if (spec := self.animations.get(state)) is not None
},
}
+ if self.acts and self.acts_sheet is not None:
+ out["acts_sheet"] = self.acts_sheet
+ out["acts"] = {name: spec_json(spec) for name, spec in self.acts.items()}
+ return out
def spec_json(spec: AnimationSpec) -> dict:
@@ -250,6 +265,8 @@ def parse_manifest(data: object, *, builtin: bool) -> PetManifest:
if state in raw_animations
}
+ acts, acts_sheet = _parse_acts(data, sheet)
+
return PetManifest(
id=pet_id,
name=name,
@@ -258,9 +275,43 @@ def parse_manifest(data: object, *, builtin: bool) -> PetManifest:
sheet=sheet,
animations=MappingProxyType(animations),
builtin=builtin,
+ acts=MappingProxyType(acts),
+ acts_sheet=acts_sheet,
)
+def _parse_acts(data: Mapping, sheet: str) -> tuple[dict[str, AnimationSpec], str | None]:
+ """The optional idle acts and their sheet; both keys or neither."""
+ raw_acts = data.get("acts")
+ acts_sheet = data.get("acts_sheet")
+ if raw_acts is None and acts_sheet is None:
+ return {}, None
+ if not isinstance(raw_acts, Mapping) or not raw_acts:
+ raise PetManifestError("'acts' must be an object with at least one act.")
+ if (
+ not isinstance(acts_sheet, str)
+ or not _SHEET_NAME_RE.match(acts_sheet)
+ or ".." in acts_sheet
+ or acts_sheet == sheet
+ ):
+ raise PetManifestError("'acts_sheet' must be its own PNG file name inside the pet folder.")
+ if len(raw_acts) > MAX_ACTS:
+ raise PetManifestError(f"A pet can have at most {MAX_ACTS} idle acts.")
+ acts: dict[str, AnimationSpec] = {}
+ for name, raw in raw_acts.items():
+ if not isinstance(name, str) or not ACT_NAME_RE.match(name):
+ raise PetManifestError(
+ "An act name uses 1-24 lowercase letters, digits and underscores."
+ )
+ if isinstance(raw, Mapping) and "loop" not in raw:
+ raw = {**raw, "loop": False} # an act plays once unless it says otherwise
+ spec = _parse_animation(f"act {name}", raw)
+ if spec.loop or spec.accent_frames:
+ raise PetManifestError(f"Act '{name}' plays once: 'loop' must be false.")
+ acts[name] = spec
+ return acts, acts_sheet
+
+
def check_sheet_size(width: int, height: int) -> None:
"""Reject a sheet larger than ``MAX_SHEET_EDGE`` on either side."""
if width < 1 or height < 1:
@@ -278,3 +329,12 @@ def check_cells(manifest: PetManifest, width: int, height: int) -> None:
for state, spec in manifest.animations.items():
if (spec.row + 1) * size > height or spec.frames * size > width:
raise PetManifestError(f"Animation '{state}' reaches outside the sprite sheet.")
+
+
+def check_act_cells(manifest: PetManifest, width: int, height: int) -> None:
+ """Reject idle acts that reach outside a ``width x height`` acts sheet."""
+ check_sheet_size(width, height)
+ size = manifest.frame_size
+ for name, spec in manifest.acts.items():
+ if (spec.row + 1) * size > height or spec.frames * size > width:
+ raise PetManifestError(f"Act '{name}' reaches outside the acts sheet.")
diff --git a/jarvis/ui/pets/store.py b/jarvis/ui/pets/store.py
index c6b189a42d..3f24a42bd6 100644
--- a/jarvis/ui/pets/store.py
+++ b/jarvis/ui/pets/store.py
@@ -121,6 +121,10 @@ class PetStore:
data: dict = {}
if manifest_json is not None and manifest_json.strip():
data = _manifest_data(manifest_json)
+ # An upload is ONE sheet: idle acts would point at a file that
+ # never arrives, so they are dropped rather than rejected.
+ data.pop("acts", None)
+ data.pop("acts_sheet", None)
if frame_size is None and "frame_size" in data:
frame_size = data["frame_size"]
size = _pick_frame_size(width, height, frame_size)
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index ce2684b775..c69e471bf8 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -6012,9 +6012,6 @@
"shelly": {
"description": "Eine Schnecke: das Haus dreht sich beim Nachdenken, zum Schlafen zieht sie sich zurück."
},
- "pip": {
- "description": "Ein Baby mit Schnuller: plappert beim Sprechen, schläft unter einer Decke."
- },
"ember": {
"description": "Ein Babydrache: bläst beim Nachdenken Rauchringe, speit bei Erfolg Feuer."
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 173117a052..caeea6b718 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -6045,9 +6045,6 @@
"shelly": {
"description": "A snail: the shell spins while thinking, it withdraws to sleep."
},
- "pip": {
- "description": "A baby with a pacifier: babbles while talking, naps under a blanket."
- },
"ember": {
"description": "A baby dragon: blows smoke rings while thinking, breathes fire on success."
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index b9520c9858..2c56a8c493 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -6012,9 +6012,6 @@
"shelly": {
"description": "Un caracol: la concha gira al pensar y se esconde para dormir."
},
- "pip": {
- "description": "Un bebé con chupete: balbucea al hablar y duerme bajo una manta."
- },
"ember": {
"description": "Un bebé dragón: hace anillos de humo al pensar y escupe fuego al acertar."
}
diff --git a/scripts/pets/build_pets.py b/scripts/pets/build_pets.py
index 0b9ecfdf19..9dbd9a12cb 100644
--- a/scripts/pets/build_pets.py
+++ b/scripts/pets/build_pets.py
@@ -353,6 +353,9 @@ class Pose:
mouth: str = "rest"
#: 1 = the body above its waist one pixel taller, -1 = one shorter.
stretch: int = 0
+ #: The idle act this frame belongs to (``""`` outside acts); ``state`` is
+ #: then ``"idle"`` so a pet's ordinary idle drawing still applies.
+ act: str = ""
def base_pose(state: str, i: int) -> Pose:
@@ -747,6 +750,24 @@ def draw_effects(f: Frame, pose: Pose, a: Anchors) -> None:
Effect = Callable[[Frame, Pose], None]
+@dataclass(frozen=True)
+class IdleAct:
+ """One idle act: ``frames`` cells at ``fps``, played once.
+
+ ``pose(i)`` gives frame ``i``'s pose; its ``state`` stays ``"idle"`` and
+ its ``act`` names the act, so the pet's ``draw`` and ``post`` branch on
+ ``pose.act``. ``fx`` draws the act's effect layer on top. The first and
+ last frame should sit close to the idle pose: the act starts from and
+ hands back to the breathing idle row.
+ """
+
+ name: str
+ frames: int
+ fps: int
+ pose: Callable[[int], Pose]
+ fx: Effect | None = None
+
+
@dataclass(frozen=True)
class PetDesign:
id: str
@@ -765,6 +786,9 @@ class PetDesign:
#: Optional pixel pass over the finished body (before the effects), for
#: looks no mask can draw: glitch slices, a dithered fade.
post: Callable[[Image.Image, Pose], Image.Image] | None = None
+ #: Idle acts: little one-shot scenes the pet plays now and then while
+ #: nothing happens (``docs/pets.md``). Written to their own ``acts.png``.
+ acts: tuple[IdleAct, ...] = ()
def counts(self) -> Mapping[str, int]:
return {**FRAME_COUNTS, **(self.frame_counts or {})}
@@ -836,6 +860,8 @@ def _gigi_hem_phase(pose: Pose) -> int:
"""
if pose.state in ("talking", "error"):
return 0
+ if pose.act:
+ return pose.i * _GIGI_ACT_HEM.get(pose.act, 1) % len(_GIGI_TOOTH)
if pose.state == "held":
return pose.i * 3 % len(_GIGI_TOOTH) # a fast flutter: it is dangling
counts = {**FRAME_COUNTS, **_GIGI_FRAMES}
@@ -868,6 +894,9 @@ _GIGI_TYPE = (
def _gigi_arms(pose: Pose) -> tuple[Mask, Mask]:
"""The left and the right arm for this pose."""
+ if pose.act:
+ left, right = _GIGI_ACT_ARMS[pose.act][pose.i]
+ return set(_GIGI_ARMS[left]), mirrored(_GIGI_ARMS[right])
if pose.state == "working":
return set(_GIGI_ARMS["rest"]), set(_GIGI_TYPE[pose.i % 2])
if pose.state == "searching":
@@ -907,6 +936,8 @@ def _gigi_bits(f: Frame, pose: Pose) -> None:
"""Idle bits twinkle one or two at a time; thinking and errors make them jitter."""
if pose.state in ("success", "sleeping", "working", "held"):
return
+ if pose.act in ("boo", "juggle_bits") and 0 < pose.i < 7:
+ return # the bits are busy: bursting, or up in the air
for k, bit in enumerate(_GIGI_BITS):
if pose.state in ("thinking", "error", "searching"):
f.paint(shifted(bit, (pose.i + 2 * k) % 3 - 1, 0), GIGI_BIT)
@@ -970,12 +1001,18 @@ def draw_gigi(f: Frame, pose: Pose) -> None:
body = _gigi_body(_gigi_hem_phase(pose))
if pose.state == "thinking":
_gigi_bit_ring(f, pose.i, front=False)
+ if pose.act == "juggle_bits":
+ _gigi_juggled_bits(f, pose.i) # behind the body: the low arc passes back
f.part(body, shade(body, GIGI_BODY, rim=GIGI_WHITE))
for side in _gigi_arms(pose):
f.paint(outer_ring(side) - body, OUTLINE)
f.paint(side, GIGI_WHITE)
band = _GIGI_TALK_BANDS.get(pose.mouth, GIGI_BAND) if pose.state == "talking" else GIGI_BAND
f.paint(rect(12, 26, 35, 26) | rect(12, 34, 35, 34), band)
+ if pose.eyes == "hidden":
+ # The coin flip's back side: no face, just the bands.
+ _gigi_bits(f, pose)
+ return
cheek = rect(13, 22, 15, 23)
f.paint(cheek | mirrored(cheek), GIGI_CHEEK)
if pose.state == "thinking":
@@ -987,6 +1024,8 @@ def draw_gigi(f: Frame, pose: Pose) -> None:
else:
draw_eyes(f, pose.eyes, (17, 18), (27, 18), GIGI_EYES)
_gigi_mouth(f, pose.mouth)
+ if pose.act == "loading":
+ _gigi_loading_bar(f, pose.i)
_gigi_bits(f, pose)
if pose.state == "thinking":
_gigi_bit_ring(f, pose.i, front=True)
@@ -1204,7 +1243,240 @@ def afterimage(img: Image.Image, trail: Sequence[tuple[int, int]], color: RGBA)
return out
+# Gigi's idle acts: a ghost made of bits plays with being a signal.
+
+#: Hem drift per act frame (teeth per frame); the dance flutters.
+_GIGI_ACT_HEM = {"glitch_dance": 3, "boo": 2}
+
+_R, _U, _C, _D = "rest", "up", "cup", "droop"
+#: Arms per act frame as (left, right) ``_GIGI_ARMS`` styles.
+_GIGI_ACT_ARMS: dict[str, tuple[tuple[str, str], ...]] = {
+ "phase_out": ((_R, _R),) * 5 + ((_U, _U), (_C, _C), (_R, _R)),
+ "glitch_dance": (
+ (_R, _R),
+ (_U, _R),
+ (_R, _U),
+ (_U, _R),
+ (_R, _U),
+ (_U, _U),
+ (_D, _D),
+ (_R, _R),
+ ),
+ "boo": ((_R, _R), (_D, _D), (_C, _C), (_U, _U), (_U, _U), (_U, _U), (_C, _C), (_R, _R)),
+ "coin_flip": ((_R, _R), (_U, _U), (_U, _U), (_U, _U), (_U, _U), (_U, _U), (_U, _U), (_R, _R)),
+ "juggle_bits": ((_R, _R), (_U, _R), (_R, _U), (_U, _R), (_R, _U), (_U, _R), (_R, _U), (_R, _R)),
+ "loading": ((_R, _R),) * 6 + ((_U, _U), (_R, _R)),
+}
+
+#: 4 x 4 ordered dither: a pixel drops out once the fade passes its rank.
+_GIGI_BAYER = ((0, 8, 2, 10), (12, 4, 14, 6), (3, 11, 1, 9), (15, 7, 13, 5))
+
+
+def gigi_vanish(img: Image.Image, level: int) -> Image.Image:
+ """Dither the figure away from the hem up: ``level`` 0 keeps it, 16 drops
+ the bottom rows entirely; the head goes about a step later than the hem."""
+ out = img.copy()
+ for y in range(CELL):
+ local = level + (y - 24) // 8
+ if local <= 0:
+ continue
+ for x in range(CELL):
+ if _GIGI_BAYER[y % 4][x % 4] < local:
+ out.putpixel((x, y), (0, 0, 0, 0))
+ return out
+
+
+#: Phase out: the fade level and where Gigi stands per frame. It dithers
+#: away where it is, then pops back five pixels to the right and drifts home.
+_GIGI_PHASE_FADE = (0, 3, 7, 11, 15, 0, 0, 0)
+_GIGI_PHASE_DX = (0, 0, 0, 0, 0, 5, 3, 1)
+
+
+def _gigi_phase_pose(i: int) -> Pose:
+ eyes = ("open", "closed", "closed", "closed", "closed", "wide", "look:-1", "open")[i]
+ mouth = ("rest", "closed", "closed", "closed", "closed", "open", "rest", "rest")[i]
+ return Pose("idle", i, dx=_GIGI_PHASE_DX[i], dy=_GIGI_FLOAT[min(i, 6)], eyes=eyes, mouth=mouth)
+
+
+def _gigi_phase_fx(f: Frame, pose: Pose) -> None:
+ """The pop: a ring of bits flashes where Gigi re-forms, then a dim one."""
+ if pose.i not in (5, 6):
+ return
+ color = GIGI_WHITE if pose.i == 5 else GIGI_BIT
+ reach = 18 if pose.i == 5 else 21
+ for ux, uy in _GIGI_BURST_DIRS[1::2]:
+ x = pose.dx + round(CX + ux * reach)
+ y = pose.dy + round(25 + uy * (reach + 2))
+ f.part({(x, y)}, color)
+
+
+#: Glitch dance: the side-step per frame and the torn slices,
+#: ``(y0, y1, dx)``, whose bright half trails white and dim half grey.
+_GIGI_DANCE_DX = (0, -2, 2, -2, 2, -1, 1, 0)
+_GIGI_DANCE_SLICES: tuple[tuple[tuple[int, int, int], ...], ...] = (
+ (),
+ ((12, 16, 2), (28, 31, -2)),
+ ((18, 22, -3), (35, 40, 2)),
+ ((10, 13, -2), (24, 27, 3)),
+ ((15, 20, 3), (31, 34, -2)),
+ ((21, 25, -2),),
+ ((13, 15, 1), (36, 39, -1)),
+ (),
+)
+
+
+def _gigi_dance_pose(i: int) -> Pose:
+ eyes = ("open", "look:-1", "look:1", "look:-1", "look:1", "happy", "happy", "open")[i]
+ mouth = ("rest", "smile", "smile", "smile", "smile", "wide", "smile", "rest")[i]
+ dy = (0, -1, 0, -1, 0, -2, -1, 0)[i]
+ return Pose("idle", i, dx=_GIGI_DANCE_DX[i], dy=dy, eyes=eyes, mouth=mouth)
+
+
+def _gigi_dance_post(img: Image.Image, pose: Pose) -> Image.Image:
+ """Each slice tears twice: a white fringe one way, a grey ghost the other."""
+ for y0, y1, dx in _GIGI_DANCE_SLICES[pose.i]:
+ img = glitch_slices(img, [(y0 + pose.dy, y1 + pose.dy, dx)], GIGI_WHITE)
+ back = -1 if dx > 0 else 1
+ img = glitch_slices(img, [(y0 + pose.dy, y1 + pose.dy, back)], GIGI_BAND)
+ return img
+
+
+def _gigi_dance_fx(f: Frame, pose: Pose) -> None:
+ """Loose scanline dashes kicked off by each step."""
+ if pose.i in (0, 7):
+ return
+ for k, y in enumerate((14, 30)):
+ x = 3 if (pose.i + k) % 2 else 40
+ f.part(rect(x, y + pose.dy + 2 * k, x + 3, y + pose.dy + 2 * k), GIGI_BIT)
+
+
+#: Boo: Gigi breathes in, puffs up, roars "BOO" at the viewer, then giggles.
+_GIGI_BOO_DY = (0, -1, -2, -1, -1, -1, -1, 0)
+_GIGI_BOO_DX = (0, 0, 0, 1, -1, 0, 0, 0)
+
+
+def _gigi_boo_pose(i: int) -> Pose:
+ eyes = ("open", "closed", "closed", "wide", "wide", "wide", "happy", "open")[i]
+ mouth = ("rest", "closed", "closed", "wide", "wide", "open", "smile", "rest")[i]
+ stretch = 1 if 2 <= i <= 5 else 0
+ return Pose(
+ "idle", i, dx=_GIGI_BOO_DX[i], dy=_GIGI_BOO_DY[i], eyes=eyes, mouth=mouth, stretch=stretch
+ )
+
+
+_GIGI_LETTERS = {
+ "B": ("##.", "#.#", "##.", "#.#", "##."),
+ "O": (".#.", "#.#", "#.#", "#.#", ".#."),
+}
+
+
+def _gigi_boo_fx(f: Frame, pose: Pose) -> None:
+ """The word "BOO" pops above the head while the loose bits burst out."""
+ if 3 <= pose.i <= 5:
+ y = 1 if pose.i == 4 else 2
+ # One glyph for the word: the 1 px gaps between letters take the outline.
+ rows = [".".join(_GIGI_LETTERS[c][r] for c in "BOO") for r in range(5)]
+ f.glyph(18 + pose.dx, y, rows, {"#": GIGI_WHITE})
+ if 3 <= pose.i <= 6:
+ _gigi_burst(f, pose.i - 2)
+
+
+#: Coin flip: the body's width per frame and whether its back faces us.
+#: It turns flat like a coin on edge and comes round to the front again.
+_GIGI_COIN = ((1.0, False), (0.55, False), (0.15, False), (0.55, True), (1.0, True),
+ (0.55, True), (0.15, False), (0.7, False)) # fmt: skip
+_GIGI_COIN_DY = (0, -1, -2, -3, -3, -2, -1, 0)
+
+
+def _gigi_coin_pose(i: int) -> Pose:
+ back = _GIGI_COIN[i][1]
+ eyes = "hidden" if back else ("open", "wide", "wide", "", "", "", "wide", "happy")[i]
+ mouth = "rest" if back else ("rest", "open", "open", "", "", "", "open", "smile")[i]
+ return Pose("idle", i, dy=_GIGI_COIN_DY[i], eyes=eyes, mouth=mouth)
+
+
+def _gigi_coin_fx(f: Frame, pose: Pose) -> None:
+ """A glint on the coin's edge at the two thinnest moments."""
+ if _GIGI_COIN[pose.i][0] < 0.2:
+ fx_sparkles(f, 1, ((CX + 5, 8 + pose.dy, 0),), GIGI_SPARK)
+
+
+#: Juggling: three bits ride a tall ellipse — up out of one hand, over the
+#: head, down into the other and back behind the body.
+_GIGI_JUGGLE_RX, _GIGI_JUGGLE_RY, _GIGI_JUGGLE_CY = 18.0, 15.0, 18.0
+
+
+def _gigi_juggle_pose(i: int) -> Pose:
+ eyes = ("open", "up_left", "up_right", "up_left", "up_right", "up_left", "up_right", "open")[i]
+ return Pose("idle", i, dy=_GIGI_FLOAT[min(i, 6)], eyes=eyes, mouth="rest")
+
+
+def _gigi_juggled_bits(f: Frame, i: int) -> None:
+ """The three bits in flight (frames 1-6); the body hides the low arc."""
+ if not 0 < i < 7:
+ return
+ for k in range(3):
+ angle = 2.0 * math.pi * ((i - 1) / 8.0 + k / 3.0)
+ x = math.floor(CX + round(_GIGI_JUGGLE_RX * math.cos(angle), 6)) - 1
+ y = math.floor(_GIGI_JUGGLE_CY - round(_GIGI_JUGGLE_RY * math.sin(angle), 6)) - 1
+ bit = rect(x, y, x + 1, y + 1)
+ f.part(bit, GIGI_WHITE if k == 0 else GIGI_BIT)
+
+
+#: Loading: how many of the bar's seven segments are full per frame.
+_GIGI_LOAD = (0, 1, 2, 4, 5, 6, 7, 0)
+
+
+def _gigi_loading_pose(i: int) -> Pose:
+ eyes = ("open", "down", "down", "down", "down", "down", "happy", "open")[i]
+ mouth = ("rest", "closed", "closed", "closed", "closed", "closed", "smile", "rest")[i]
+ return Pose("idle", i, dy=-1 if i == 6 else 0, eyes=eyes, mouth=mouth)
+
+
+def _gigi_loading_bar(f: Frame, i: int) -> None:
+ """A progress bar across the upper band, filling in 2 px segments."""
+ if not 0 < i < 7:
+ return
+ f.paint(outer_ring(rect(13, 25, 34, 27)) - rect(11, 24, 11, 28) - rect(36, 24, 36, 28),
+ GIGI_WHITE) # fmt: skip
+ f.paint(rect(13, 25, 34, 27), GIGI_BODY)
+ for seg in range(_GIGI_LOAD[i]):
+ x = 13 + 3 * seg
+ f.paint(rect(x, 25, x + 1, 27), GIGI_WHITE if i < 6 else GIGI_BIT)
+
+
+def _gigi_loading_fx(f: Frame, pose: Pose) -> None:
+ """Done: a sparkle at each end of the full bar."""
+ if pose.i == 6:
+ fx_sparkles(f, 1, ((7, 21 + pose.dy, 0), (40, 21 + pose.dy, 0)), GIGI_SPARK)
+
+
+def _gigi_act_post(img: Image.Image, pose: Pose) -> Image.Image:
+ """The pixel pass of an idle act (fades, tears, a coin's turn, a puff)."""
+ if pose.act == "phase_out":
+ return gigi_vanish(img, _GIGI_PHASE_FADE[pose.i])
+ if pose.act == "glitch_dance":
+ return _gigi_dance_post(img, pose)
+ if pose.act == "coin_flip":
+ return squash_x(img, _GIGI_COIN[pose.i][0])
+ if pose.act == "boo" and 3 <= pose.i <= 4:
+ return ghost_aura(img, 1, GIGI_BAND)
+ return img
+
+
+GIGI_ACTS = (
+ IdleAct("phase_out", 8, 8, _gigi_phase_pose, _gigi_phase_fx),
+ IdleAct("glitch_dance", 8, 10, _gigi_dance_pose, _gigi_dance_fx),
+ IdleAct("boo", 8, 8, _gigi_boo_pose, _gigi_boo_fx),
+ IdleAct("coin_flip", 8, 10, _gigi_coin_pose, _gigi_coin_fx),
+ IdleAct("juggle_bits", 8, 8, _gigi_juggle_pose),
+ IdleAct("loading", 8, 7, _gigi_loading_pose, _gigi_loading_fx),
+)
+
+
def gigi_post(img: Image.Image, pose: Pose) -> Image.Image:
+ if pose.act:
+ return _gigi_act_post(img, pose)
if pose.state == "success":
return squash_x(img, _GIGI_SPIN[pose.i])
if pose.state == "talking" and pose.mouth in ("open", "wide"):
@@ -1258,6 +1530,7 @@ GIGI = PetDesign(
"searching": _gigi_lens_fx,
"held": _gigi_held_fx,
},
+ acts=GIGI_ACTS,
)
@@ -1435,7 +1708,9 @@ def _miso_bristle(f: Frame, i: int) -> None:
def draw_miso(f: Frame, pose: Pose) -> None:
- if pose.state == "sleeping":
+ if pose.act:
+ _MISO_ACT_BODIES[pose.act](f, pose)
+ elif pose.state == "sleeping":
_draw_miso_curled(f, pose)
elif pose.state == "searching":
_draw_miso_stalking(f, pose)
@@ -1603,6 +1878,226 @@ def _draw_miso_curled(f: Frame, pose: Pose) -> None:
f.paint(rect(16, 34, 17, 34), MISO_NOSE)
+# Idle acts: the bodies. Each act draws the sitting cat with its own paw,
+# ear, tail and mouth per frame; the props (yarn, butterfly, cup) are effects.
+
+#: Shoulders the raised front legs grow from (left, right).
+_MISO_SHOULDERS: tuple[Px, Px] = ((18, 37), (30, 37))
+#: The tail straight up and quivering: excitement or a big stretch.
+_MISO_TAIL_UP = thick(polyline([(33, 41), (37, 39), (39, 35), (40, 29), (40, 24), (41, 21)]))
+
+
+def _miso_arm(f: Frame, start: Px, paw: tuple[float, float]) -> None:
+ """A front leg lifted from the shoulder ``start`` to a paw centred on ``paw``."""
+ _miso_fur(f, thick(thick(line(*start, math.floor(paw[0]), math.floor(paw[1])))), 1)
+ _miso_paw(f, *paw, 2.4, 2)
+
+
+def _miso_act_sit(
+ f: Frame,
+ pose: Pose,
+ *,
+ ears: tuple[str, str] = ("rest", "rest"),
+ tail: Mask | None = None,
+ paws: tuple[bool, bool] = (True, True),
+ head_dx: int = 0,
+ whiskers: int = 0,
+) -> None:
+ """The sitting cat every act starts from: tail, body, the planted front
+ paws and the head, which can lean ``head_dx`` on its own."""
+ _miso_fur(f, _miso_tail(0) if tail is None else tail, 1)
+ _miso_fur(f, ellipse(CX, 37, 10, 7))
+ f.paint(ellipse(CX, 38, 5, 4), MISO_CREAM)
+ for planted, cx in zip(paws, (19.5, 28.5), strict=True):
+ if planted:
+ _miso_paw(f, cx, 43)
+ with f.offset(head_dx, 0):
+ _miso_head(f, pose, ears, whiskers=whiskers)
+
+
+#: Yarn: the tail tip twitches faster as the ball comes closer.
+_MISO_YARN_TAIL = ((0, 0), (1, 2), (1, 3), (2, 3), (2, 3), (1, 2), (0, 1), (0, 0))
+#: Yarn: the left paw per frame, ``None`` while it is planted: up as the ball
+#: stops, wound up higher, then the swat down where the ball was.
+_MISO_YARN_PAW: tuple[tuple[float, float] | None, ...] = (
+ None,
+ None,
+ None,
+ (14.5, 34),
+ (12.5, 30),
+ (11.5, 40),
+ (15.5, 38),
+ None,
+)
+
+
+def _draw_miso_yarn(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ paw = _MISO_YARN_PAW[i]
+ with f.offset(pose.dx, pose.dy):
+ _miso_act_sit(
+ f,
+ pose,
+ ears=("perk", "perk") if 2 <= i <= 5 else ("rest", "rest"),
+ tail=_miso_tail(*_MISO_YARN_TAIL[i]),
+ paws=(paw is None, True),
+ )
+ if paw is not None:
+ _miso_arm(f, _MISO_SHOULDERS[0], paw)
+
+
+#: Grooming: the right paw per frame: up to the mouth, licked three times,
+#: wiped over the eye and down the cheek.
+_MISO_GROOM_PAW: tuple[tuple[float, float] | None, ...] = (
+ None,
+ (28.5, 33),
+ (28.5, 30),
+ (28.5, 29),
+ (28.5, 30),
+ (29.5, 22),
+ (31.5, 26),
+ None,
+)
+
+
+def _draw_miso_groom(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ paw = _MISO_GROOM_PAW[i]
+ ears = {5: ("rest", "flick"), 6: ("rest", "swivel")}.get(i, ("rest", "rest"))
+ with f.offset(pose.dx, pose.dy):
+ _miso_act_sit(f, pose, ears=ears, paws=(True, paw is None))
+ if paw is not None:
+ _miso_arm(f, _MISO_SHOULDERS[1], paw)
+ if i in (2, 4):
+ f.paint({(24, 28), (25, 28), (25, 29)}, TONGUE) # a long lick
+ elif i == 3:
+ f.paint({(24, 28)}, TONGUE)
+
+
+#: Yawning: how far the mouth opens per frame (0 = the pose's own mouth).
+_MISO_YAWN = (0, 0, 1, 2, 3, 3, 1, 0)
+
+
+def _miso_yawn_mouth(f: Frame, size: int, curl: bool) -> None:
+ """A yawn ``size`` rows deeper than a plain open mouth: fangs at the top,
+ the tongue at the bottom, its tip curling up at the widest."""
+ top, bottom = 27, 28 + size
+ mouth = rect(21, top, 26, bottom) - {(21, bottom), (26, bottom)}
+ f.part(mouth, MOUTH_DARK)
+ f.paint(rect(22, bottom, 25, bottom), TONGUE)
+ if size >= 3:
+ f.paint({(22, bottom - 1), (25, bottom - 1)} if curl else {(22, bottom - 1)}, TONGUE)
+ f.paint({(22, top), (25, top)}, FX_WHITE) # the fangs
+ f.paint(rect(23, 25, 24, 25), MISO_NOSE)
+
+
+def _draw_miso_yawn(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ size = _MISO_YAWN[i]
+ peak = 3 <= i <= 5
+ with f.offset(pose.dx, pose.dy):
+ _miso_act_sit(
+ f,
+ pose,
+ ears=("back", "back") if size >= 2 else ("rest", "rest"),
+ tail=_MISO_TAIL_UP if peak else None,
+ paws=(not peak, not peak),
+ whiskers=min(size, 2),
+ )
+ if peak:
+ # The front paws pushed forward and splayed: a full-body stretch.
+ _miso_paw(f, 17.5, 43.5, 3.6, 2)
+ _miso_paw(f, 30.5, 43.5, 3.6, 2)
+ if size:
+ _miso_yawn_mouth(f, size, curl=i == 5)
+
+
+#: Butterfly: the head leans after it (x offset per frame).
+_MISO_BFLY_HEAD = (1, 1, 0, 0, -1, -1, -1, 0)
+#: Butterfly: the left paw winds up as it passes, then swipes high.
+_MISO_BFLY_PAW: tuple[tuple[float, float] | None, ...] = (
+ None,
+ None,
+ None,
+ None,
+ None,
+ (15.5, 33),
+ (12.5, 22),
+ None,
+)
+
+
+def _draw_miso_butterfly(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ paw = _MISO_BFLY_PAW[i]
+ with f.offset(pose.dx, pose.dy):
+ _miso_act_sit(
+ f,
+ pose,
+ ears=("perk", "perk") if 1 <= i <= 6 else ("rest", "rest"),
+ tail=_miso_tail(*_MISO_YARN_TAIL[i]),
+ paws=(paw is None, True),
+ head_dx=_MISO_BFLY_HEAD[i],
+ )
+ if paw is not None:
+ _miso_arm(f, _MISO_SHOULDERS[0], paw)
+
+
+#: Loaf: how far the cat has settled per frame (0 sitting, 1 halfway, 2 a loaf).
+_MISO_LOAF = (0, 0, 1, 2, 2, 2, 1, 0)
+
+
+def _draw_miso_loaf(f: Frame, pose: Pose) -> None:
+ """Sitting down into a loaf: the head sinks, the body spreads, the front
+ paws tuck under and the tail wraps round the front, then back up."""
+ depth = _MISO_LOAF[pose.i]
+ if depth == 0:
+ with f.offset(pose.dx, pose.dy):
+ _miso_act_sit(f, pose)
+ return
+ with f.offset(pose.dx, pose.dy):
+ tail = thick(polyline([(34, 42), (31, 44), (18, 44), (14, 43)]))
+ body = ellipse(CX, 38 + depth / 2, 10 + 1.5 * depth, 7 - depth / 2)
+ _miso_fur(f, body)
+ f.paint(rect(31, 34, 32, 35) | rect(15, 34, 16, 35), MISO_STRIPE)
+ if depth == 1:
+ _miso_paw(f, 19.5, 43.5, 2.4, 1.6)
+ _miso_paw(f, 28.5, 43.5, 2.4, 1.6)
+ else:
+ _miso_fur(f, tail, 1)
+ with f.offset(0, 2 * depth):
+ _miso_head(f, pose)
+
+
+#: Knocking the cup: the right paw reaches out, taps, pushes and follows through.
+_MISO_CUP_PAW: tuple[tuple[float, float] | None, ...] = (
+ None,
+ None,
+ None,
+ (35.5, 39),
+ (37.5, 39),
+ (38.5, 38),
+ None,
+ None,
+)
+
+
+def _draw_miso_knock_cup(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ paw = _MISO_CUP_PAW[i]
+ with f.offset(pose.dx, pose.dy):
+ # The tail swings round to the left, out of the cup's way.
+ _miso_act_sit(
+ f,
+ pose,
+ ears=("perk", "perk") if i in (1, 5) else ("rest", "rest"),
+ tail=mirrored(_miso_tail(*_MISO_IDLE_TAIL[i % len(_MISO_IDLE_TAIL)])),
+ paws=(True, paw is None),
+ )
+ if paw is not None:
+ _miso_arm(f, _MISO_SHOULDERS[1], paw)
+
+
# -- Miso's effects -----------------------------------------------------------
_MISO_HEART_S = ("#.#", "###", ".#.")
@@ -1718,6 +2213,248 @@ def _miso_sleeping_fx(f: Frame, pose: Pose) -> None:
f.paint({(gx, gy)}, FX_WHITE)
+MISO_YARN = hexc("#e5566e")
+MISO_YARN_LIGHT = hexc("#ff96a8")
+MISO_YARN_DARK = hexc("#9e2f48")
+MISO_WING = hexc("#7fc4ff")
+MISO_CUP = hexc("#f2f4fa")
+MISO_COFFEE = hexc("#6b3e26")
+
+
+def _miso_clip(f: Frame) -> None:
+ """Drop whatever a prop painted outside the cell (it rolls or falls out)."""
+ for p in [p for p in f.px if not (0 <= p[0] < CELL and 0 <= p[1] < CELL)]:
+ del f.px[p]
+
+
+#: The ball of yarn per frame (centre), ``None`` once it is gone: rolls in from
+#: the left, stops at the paw, waits, and flies off after the swat.
+_MISO_YARN_BALL: tuple[Px | None, ...] = (
+ (1, 42),
+ (6, 42),
+ (10, 42),
+ (11, 42),
+ (11, 42),
+ (4, 36),
+ (0, 31),
+ None,
+)
+
+
+def _miso_yarn_fx(f: Frame, pose: Pose) -> None:
+ """A ball of yarn that rolls in trailing a loose thread, its strands turning
+ as it rolls, and flies away once it is swatted."""
+ spot = _MISO_YARN_BALL[pose.i]
+ if spot is None:
+ return
+ x, y = spot
+ flying = pose.i >= 5
+ if flying:
+ f.paint(polyline([(x + 2, y + 2), (x + 5, y + 3), (x + 7, y + 6)]), MISO_YARN_DARK)
+ else:
+ f.paint(line(x - 3, y + 3, x - 9, y + 3), MISO_YARN_DARK)
+ ball = ellipse(x + 0.5, y + 0.5, 3.5, 3.5)
+ f.part(ball, shade(ball, MISO_YARN, light=MISO_YARN_LIGHT, dark=MISO_YARN, dark_depth=1))
+ turn = pose.i if pose.i < 3 else (3 if flying else 0) + pose.i
+ strands = (
+ line(x - 2, y - 1, x + 2, y + 2) | line(x - 1, y - 2, x + 2, y + 1),
+ line(x, y - 2, x, y + 3) | line(x + 2, y - 2, x + 2, y + 2),
+ line(x - 2, y + 2, x + 2, y - 1) | line(x - 1, y + 3, x + 3, y),
+ )[turn % 3]
+ f.paint(strands & ball, MISO_YARN_DARK)
+ _miso_clip(f)
+
+
+#: The butterfly per frame: centre and whether its wings are open. It drifts
+#: in from the top right, past the ears, and escapes the swipe up and away.
+_MISO_BFLY: tuple[tuple[int, int, bool], ...] = (
+ (44, 13, True),
+ (39, 7, False),
+ (33, 4, True),
+ (26, 7, False),
+ (19, 4, True),
+ (13, 8, False),
+ (8, 3, True),
+ (3, 1, False),
+)
+_MISO_WINGS_OPEN = ("ww...ww", "wwwbwww", "wowbwow", ".wwbww.")
+_MISO_WINGS_SHUT = (".w.w.", ".wbw.", ".wbw.", "..b..")
+
+
+def _miso_butterfly_fx(f: Frame, pose: Pose) -> None:
+ """A little blue butterfly flutters past, flapping on every frame."""
+ x, y, spread = _MISO_BFLY[pose.i]
+ rows = _MISO_WINGS_OPEN if spread else _MISO_WINGS_SHUT
+ palette = {"w": MISO_WING, "o": SPARK, "b": OUTLINE}
+ f.glyph(x - len(rows[0]) // 2, y - 1, rows, palette)
+ _miso_clip(f)
+
+
+def _miso_loaf_fx(f: Frame, pose: Pose) -> None:
+ """A purr hums out of the loaf, and a small heart floats up."""
+ if _MISO_LOAF[pose.i] < 2:
+ return
+ buzz = pose.i % 2
+ f.paint({(7, 38 + buzz), (7, 41 + buzz), (40, 38 + buzz), (40, 41 + buzz)}, ARC_FADE)
+ if pose.i == 4:
+ f.glyph(37, 20, _MISO_HEART_S, _MISO_HEART_PALETTE)
+ elif pose.i == 5:
+ f.glyph(37, 17, _MISO_HEART_S, _MISO_HEART_PALETTE)
+
+
+#: A little cup, rim of coffee on top, a blue band and the handle on the right.
+_MISO_CUP_ROWS = (
+ "cccccc..",
+ "wwwwwwww",
+ "wwwwww.w",
+ "bbbbbb.w",
+ "wwwwwwww",
+ "wwwwww..",
+ ".wwww...",
+)
+_MISO_CUP_PALETTE = {"c": MISO_COFFEE, "w": MISO_CUP, "b": ARC}
+
+
+def _miso_cup_rows(i: int) -> tuple[Px, tuple[str, ...]] | None:
+ """Where the cup's top-left sits and how it is turned in frame ``i``."""
+ rows = _MISO_CUP_ROWS
+ if i <= 3:
+ return (38, 38), rows
+ if i == 4:
+ # Pushed: the top tips a pixel over the edge.
+ return (38, 38), tuple("." + r if k < 3 else r + "." for k, r in enumerate(rows))
+ if i == 5:
+ # Off the ground and tipping further, on its way over the edge.
+ lean = tuple((6 - k) // 3 for k in range(len(rows)))
+ return (37, 33), tuple("." * n + r + "." * (2 - n) for n, r in zip(lean, rows, strict=True))
+ return None
+
+
+def _miso_knock_cup_fx(f: Frame, pose: Pose) -> None:
+ """A cup pops up beside Miso, gets pushed, flies off tipping and crashes."""
+ i = pose.i
+ placed = _miso_cup_rows(i)
+ if placed is not None:
+ (x, y), rows = placed
+ f.glyph(x, y, rows, _MISO_CUP_PALETTE)
+ if i == 0:
+ f.glyph(43, 32, _SPARK_S, _SPARK_PALETTE) # it just appeared
+ elif i == 5:
+ f.paint({(37, 35), (38, 34), (37, 38)}, ARC) # whoosh
+ f.part({(45, 31), (47, 33)}, MISO_COFFEE) # the splash
+ elif i == 6:
+ # The crash: shards and a splash at the bottom right.
+ for p in ((41, 45), (45, 43), (44, 46)):
+ f.part({p}, MISO_CUP)
+ f.part({(42, 42)}, MISO_COFFEE)
+ f.paint(line(38, 40, 40, 42) | line(46, 39, 45, 41) | {(42, 39), (42, 38)}, ARC)
+ _miso_clip(f)
+
+
+MISO_ACTS = (
+ IdleAct(
+ "yarn_play",
+ 8,
+ 8,
+ lambda i: Pose(
+ "idle",
+ i,
+ dx=(0, 0, 0, 0, -1, -1, 0, 0)[i],
+ eyes=(
+ "open",
+ "look_left",
+ "look_left",
+ "wide",
+ "look_left",
+ "happy",
+ "look_left",
+ "open",
+ )[i],
+ mouth=("rest", "rest", "closed", "half", "closed", "smile", "smile", "rest")[i],
+ ),
+ _miso_yarn_fx,
+ ),
+ IdleAct(
+ "groom",
+ 8,
+ 8,
+ lambda i: Pose(
+ "idle",
+ i,
+ eyes=("open", "down", "closed", "closed", "closed", "closed", "closed", "happy")[i],
+ mouth="closed" if 2 <= i <= 4 else "rest",
+ ),
+ ),
+ IdleAct(
+ "big_yawn",
+ 8,
+ 8,
+ lambda i: Pose(
+ "idle",
+ i,
+ eyes=("open", "half", "happy", "happy", "happy", "happy", "half", "closed")[i],
+ mouth="rest" if i == 0 else "closed",
+ stretch=(0, 1, 1, 1, 1, 1, 0, 0)[i],
+ ),
+ ),
+ IdleAct(
+ "butterfly",
+ 8,
+ 8,
+ lambda i: Pose(
+ "idle",
+ i,
+ eyes=(
+ "look_right",
+ "up_right",
+ "up_right",
+ "wide",
+ "up_left",
+ "up_left",
+ "wide",
+ "up_left",
+ )[i],
+ mouth="half" if i == 6 else "rest",
+ ),
+ _miso_butterfly_fx,
+ ),
+ IdleAct(
+ "loaf",
+ 8,
+ 6,
+ lambda i: Pose(
+ "idle",
+ i,
+ eyes=("open", "half", "half", "happy", "closed", "happy", "half", "open")[i],
+ stretch=-1 if i == 1 else 0,
+ ),
+ _miso_loaf_fx,
+ ),
+ IdleAct(
+ "knock_cup",
+ 8,
+ 8,
+ lambda i: Pose(
+ "idle",
+ i,
+ eyes=("open", "look_right", "open", "half", "half", "look_right", "half", "half")[i],
+ mouth="smile" if i >= 6 else "rest",
+ ),
+ _miso_knock_cup_fx,
+ ),
+)
+
+#: The body drawing of each act, by name.
+_MISO_ACT_BODIES: dict[str, Callable[[Frame, Pose], None]] = {
+ "yarn_play": _draw_miso_yarn,
+ "groom": _draw_miso_groom,
+ "big_yawn": _draw_miso_yawn,
+ "butterfly": _draw_miso_butterfly,
+ "loaf": _draw_miso_loaf,
+ "knock_cup": _draw_miso_knock_cup,
+}
+
+
MISO_ANCHORS = Anchors(
arcs_left=(10, 18),
arcs_right=(37, 18),
@@ -1744,6 +2481,7 @@ MISO = PetDesign(
"searching": _miso_searching_fx,
"held": _miso_held_fx,
},
+ acts=MISO_ACTS,
)
@@ -1826,6 +2564,8 @@ def brew_pose(state: str, i: int) -> Pose:
def _brew_tilt(pose: Pose) -> float:
+ if pose.act:
+ return _BREW_ACT_TILT.get(pose.act, (0.0,) * 8)[pose.i]
return _BREW_TILT.get(pose.state, (0.0,) * 8)[pose.i]
@@ -1836,7 +2576,7 @@ def _brew_drop(x: int, pose: Pose) -> int:
def _brew_lid_lift(pose: Pose) -> int:
- lifts = _BREW_LID_LIFT.get(pose.state)
+ lifts = _BREW_ACT_LID.get(pose.act) if pose.act else _BREW_LID_LIFT.get(pose.state)
return lifts[pose.i] if lifts is not None and pose.i < len(lifts) else 0
@@ -1849,8 +2589,16 @@ def _brew_lid(pose: Pose) -> tuple[Mask, Mask]:
def place(mask: Mask) -> Mask:
return {(x + side, y - lift - max(0, x - 13) * tilt // 10) for x, y in mask}
+ face = _BREW_FLIP_FACE[pose.i] if pose.act == "lid_flip" else "dome"
+ if face == "edge":
+ # Spinning, seen edge-on: a flat disc with the knob facing the viewer.
+ return place(ellipse(BREW_AXIS, 19, 9.5, 1.6)), place(rect(21, 18, 22, 19))
dome = {p for p in ellipse(BREW_AXIS, 23, 9, 5) if p[1] <= 21}
- return place(dome), place(ellipse(*BREW_KNOB, 2, 2))
+ knob = ellipse(*BREW_KNOB, 2, 2)
+ if face == "flipped":
+ # Upside down: the dome mirrored over the lid's middle row, knob below.
+ return place({(x, 35 - y) for x, y in dome}), place({(x, 35 - y) for x, y in knob})
+ return place(dome), place(knob)
def _brew_glint(x0: int) -> Mask:
@@ -1877,7 +2625,7 @@ def draw_brew(f: Frame, pose: Pose) -> None:
body = ellipse(BREW_AXIS, 32, 13, 10)
f.part(body, _shade(body, base, light, dark, 3))
f.paint({(14, 26), (15, 25), (16, 25)}, FX_WHITE)
- if pose.state == "idle" and _BREW_GLINT[pose.i] is not None:
+ if pose.state == "idle" and not pose.act and _BREW_GLINT[pose.i] is not None:
f.paint(_brew_glint(_BREW_GLINT[pose.i]) & eroded(body, 2), light)
if pose.state == "error" and pose.i >= 2:
f.paint(_BREW_CRACK, BREW_INK)
@@ -1893,10 +2641,15 @@ def draw_brew(f: Frame, pose: Pose) -> None:
f.part(knob, BREW_GOLD)
draw_eyes(f, pose.eyes, (15, 28), (26, 28), BREW_EYES)
blush = rect(12, 33, 13, 33) | rect(30, 33, 31, 33)
- if pose.state in ("success", "held"):
+ if pose.state in ("success", "held") or pose.i in _BREW_ACT_BLUSH.get(pose.act, ()):
blush |= rect(11, 33, 11, 33) | rect(32, 33, 32, 33)
f.paint(blush, BREW_BLUSH)
- draw_mouth(f, pose.mouth, 20, 34, 4, color=BREW_INK)
+ if pose.mouth == "o":
+ # A small round whistling mouth.
+ f.paint(rect(21, 35, 22, 35), MOUTH_DARK)
+ f.paint({(21, 34), (22, 34), (20, 35), (23, 35), (21, 36), (22, 36)}, BREW_INK)
+ else:
+ draw_mouth(f, pose.mouth, 20, 34, 4, color=BREW_INK)
def _brew_cosy(f: Frame, pose: Pose) -> None:
@@ -2141,6 +2894,257 @@ def brew_post(img: Image.Image, pose: Pose) -> Image.Image:
return out
+# -- Brew's idle acts ---------------------------------------------------------
+#
+# Five little scenes Brew plays while nothing happens: the lid flips up and
+# spins (its signature), a steam ring that turns into a heart, a tiny cup of
+# tea for itself, a whistled tune and a fit of bubbly hiccups.
+
+#: Per act: how far the lid lifts in each frame (pixels).
+_BREW_ACT_LID: dict[str, tuple[int, ...]] = {
+ "lid_flip": (0, 4, 9, 12, 11, 7, 2, 0),
+ "steam_heart": (0, 1, 0, 0, 0, 0, 0, 0),
+ "pour_self": (0,) * 8,
+ "whistle_tune": (0, 1, 0, 1, 0, 1, 0, 0),
+ "bubble_hiccup": (0, 3, 1, 0, 4, 1, 0, 0),
+}
+#: Per act: the whole pot's forward tilt per frame (see ``_BREW_TILT``).
+_BREW_ACT_TILT: dict[str, tuple[float, ...]] = {
+ "pour_self": (0.0, 0.0, 0.2, 0.2, 0.0, 0.2, 0.0, 0.0),
+}
+#: Per act: the frames with the wide, happy blush.
+_BREW_ACT_BLUSH: dict[str, tuple[int, ...]] = {
+ "steam_heart": (5, 6),
+ "pour_self": (5, 6, 7),
+ "bubble_hiccup": (6,),
+}
+#: Lid flip: which side of the spinning lid faces the viewer per frame.
+_BREW_FLIP_FACE = ("dome", "dome", "edge", "flipped", "edge", "dome", "dome", "dome")
+
+
+def _brew_act_pose(name: str, **columns: Sequence[object]) -> Callable[[int], Pose]:
+ """A pose function reading frame ``i`` from per-field columns."""
+
+ def pose(i: int) -> Pose:
+ fields = {key: values[i] for key, values in columns.items()}
+ return Pose("idle", i, act=name, **fields) # type: ignore[arg-type]
+
+ return pose
+
+
+def _brew_lid_flip_fx(f: Frame, pose: Pose) -> None:
+ """The lid pops off and flips in the air; steam curls out of the open pot,
+ and the lid lands back with a clack."""
+ i = pose.i
+ if i in (2, 3, 4):
+ _brew_puffs(f, ((BREW_AXIS - 1, 17 - (i - 2), i == 3),))
+ if i == 1:
+ f.paint(line(11, 19, 9, 18) | line(32, 19, 34, 18), ARC)
+ if i == 7:
+ # The clack: ticks on both sides of the landed lid and a little spark.
+ f.paint(line(11, 18, 10, 16) | line(33, 18, 34, 16), ARC)
+ f.paint(line(9, 20, 7, 20) | line(35, 20, 37, 20), ARC_FADE)
+ fx_sparkles(f, 0, ((BREW_KNOB[0] + 6, 11, 0),))
+
+
+def _brew_ring(cx: float, cy: float, r: float) -> Mask:
+ return ellipse(cx, cy, r, r) - ellipse(cx, cy, r - 1.3, r - 1.3)
+
+
+_BREW_HEART_BIG = (".##.##.", "##o####", "#######", ".#####.", "..###..", "...#...")
+
+
+def _brew_steam_heart_fx(f: Frame, pose: Pose) -> None:
+ """Brew blows a steam ring from the spout; it rises, swells, pinches at
+ the top into a heart and floats off pink."""
+ i = pose.i
+ sx, sy = BREW_SPOUT
+ if i == 1:
+ _brew_puffs(f, ((sx, sy - 3, False),))
+ elif i == 2:
+ f.part(_brew_ring(sx - 0.5, sy - 5.5, 2.4), BREW_STEAM)
+ elif i == 3:
+ f.part(_brew_ring(sx - 2.5, sy - 9.5, 3.2), BREW_STEAM)
+ elif i == 4:
+ f.glyph(sx - 7, sy - 15, _BREW_HEART_BIG, {"#": BREW_STEAM, "o": FX_WHITE})
+ elif i == 5:
+ f.glyph(sx - 8, sy - 16, _BREW_HEART_BIG, {"#": BREW_HEART, "o": BREW_HEART_LIGHT})
+ elif i == 6:
+ f.glyph(sx - 8, sy - 18, _BREW_HEART_BIG, {"#": BREW_HEART, "o": BREW_HEART_LIGHT})
+ fx_sparkles(f, 0, ((sx - 11, sy - 17, 0),))
+ elif i == 7:
+ f.glyph(sx - 6, 1, _BREW_HEART, {"#": BREW_HEART_LIGHT, "o": FX_WHITE})
+
+
+#: Pour self: the cup's tea level per frame (None = no cup; 0 empty, 1 full).
+_BREW_CUP_FILL = (None, 0, 0, 1, 1, 1, 0, None)
+
+
+def _brew_pour_self_fx(f: Frame, pose: Pose) -> None:
+ """Brew pours itself a tiny cup, lets it steam, sips it back up the spout
+ and glows with content; the cup goes as it came, in a puff."""
+ i = pose.i
+ cx, cy = _BREW_CUP_AT
+ fill = _BREW_CUP_FILL[i]
+ if fill is None:
+ if i == len(_BREW_CUP_FILL) - 1:
+ _brew_puffs(f, ((cx + 3, cy + 2, True), (cx + 7, cy, False)))
+ return
+ if _brew_tilt(pose):
+ # The stream, as while working: down to pour, back up to sip.
+ rx = BREW_SPOUT[0] - 1 + pose.dx
+ ry = BREW_SPOUT[1] + 1 + _brew_drop(rx, pose)
+ stream = {(rx + 1, ry - 1), (rx + 2, ry - 1)} | rect(rx + 2, ry, rx + 3, cy)
+ f.part(stream, BREW_TEA)
+ for k in range(2):
+ y = cy - 3 - 4 * k if i == 5 else ry + 1 + 4 * k + (i - 2) * 2
+ f.paint({(rx + 2, y), (rx + 3, y + 1)} & stream, BREW_TEA_LIGHT)
+ cup = rounded_rect(cx, cy, cx + 7, cy + 6, 2) | {(cx, cy), (cx + 7, cy)}
+ f.part(cup, _shade(cup, BREW_CUP, FX_WHITE, BREW_CUP_DARK, 1))
+ f.paint(rect(cx + 1, cy, cx + 6, cy), BREW_TEA if fill else BREW_CUP_DARK)
+ handle = {(cx + 8, cy + 2), (cx + 9, cy + 2), (cx + 9, cy + 3), (cx + 8, cy + 4)}
+ f.part(handle - cup, BREW_CUP_DARK)
+ if i == 1:
+ fx_sparkles(f, 0, ((cx + 6, cy - 5, 0),))
+ if i == 4:
+ _brew_wisp(f, cx + 3, cy - 2, 4)
+ if i == 6:
+ f.glyph(5, 12, _BREW_HEART, {"#": BREW_HEART, "o": BREW_HEART_LIGHT})
+
+
+_BREW_NOTE = ("..##", "..#.", "..#.", "###.", "##..")
+_BREW_NOTES = (".####", ".#..#", ".#..#", "##.##", "##.##")
+#: Whistle: (first frame, glyph, colour) of each note from the spout.
+_BREW_TUNE = ((1, _BREW_NOTE, BREW_GOLD), (3, _BREW_NOTES, ARC), (5, _BREW_NOTE, BREW_HEART))
+
+
+def _brew_whistle_fx(f: Frame, pose: Pose) -> None:
+ """A happy little whistle: notes bob up out of the spout, one every two
+ frames, swaying as they rise."""
+ i = pose.i
+ sx, sy = BREW_SPOUT
+ if 1 <= i <= 6:
+ _brew_puffs(f, ((sx, sy - 2, False),))
+ for start, glyph, color in _BREW_TUNE:
+ age = i - start
+ if 0 <= age <= 3:
+ x = sx - 6 + (0, 1, 0, -1)[age] - (start % 3)
+ f.glyph(x, sy - 8 - 3 * age, glyph, {"#": color})
+
+
+_BREW_BUBBLE = (".##.", "#wo#", "#oo#", ".##.")
+_BREW_BUBBLE_S = ("#w", "##")
+_BREW_BUBBLE_PAL = {"#": BREW_LENS, "o": hexc("#d8f2ff"), "w": FX_WHITE}
+#: Hiccup: the bubbles per frame, (x, y, big) top-left; a bubble that bursts
+#: becomes a pop of four dots at an entry with ``big=None``.
+_BREW_HICCUPS: tuple[tuple[tuple[int, int, bool | None], ...], ...] = (
+ (),
+ ((10, 16, False), (32, 15, True)),
+ ((8, 12, True), (34, 10, True), (21, 9, False)),
+ ((9, 9, None), (35, 7, True), (21, 6, None)),
+ ((35, 4, None), (12, 14, False), (31, 13, False)),
+ ((10, 10, True), (33, 9, True), (19, 8, True)),
+ ((10, 7, None), (33, 6, None), (18, 4, True)),
+ ((18, 2, None),),
+)
+
+
+def _brew_hiccup_fx(f: Frame, pose: Pose) -> None:
+ """Hic! The pot jumps, the lid pops and soap bubbles bubble out of the
+ gap; they drift up and pop. Twice."""
+ for x, y, big in _BREW_HICCUPS[pose.i]:
+ if big is None:
+ f.paint({(x, y), (x + 3, y), (x, y + 3), (x + 3, y + 3)}, ARC)
+ f.paint({(x + 1, y + 1), (x + 2, y + 2)}, ARC_FADE)
+ else:
+ f.glyph(x, y, _BREW_BUBBLE if big else _BREW_BUBBLE_S, _BREW_BUBBLE_PAL)
+ if pose.i in (1, 4):
+ f.paint(line(11, 19 + pose.dy, 9, 18 + pose.dy), ARC)
+ f.paint(line(32, 19 + pose.dy, 34, 18 + pose.dy), ARC)
+
+
+BREW_ACTS = (
+ IdleAct(
+ "lid_flip",
+ 8,
+ 10,
+ _brew_act_pose(
+ "lid_flip",
+ eyes=("open", "wide", "up_left", "up_left", "up_right", "up_right", "wide", "happy"),
+ mouth=("rest", "half", "open", "open", "open", "half", "half", "smile"),
+ stretch=(0, 1, 0, 0, 0, 0, 0, -1),
+ ),
+ _brew_lid_flip_fx,
+ ),
+ IdleAct(
+ "steam_heart",
+ 8,
+ 8,
+ _brew_act_pose(
+ "steam_heart",
+ eyes=(
+ "open",
+ "look_right",
+ "up_right",
+ "up_right",
+ "up_right",
+ "happy",
+ "happy",
+ "open",
+ ),
+ mouth=("rest", "o", "closed", "closed", "rest", "smile", "smile", "rest"),
+ ),
+ _brew_steam_heart_fx,
+ ),
+ IdleAct(
+ "pour_self",
+ 8,
+ 7,
+ _brew_act_pose(
+ "pour_self",
+ dx=(0, -1, -2, -2, -2, -2, -1, 0),
+ eyes=(
+ "open",
+ "look_right",
+ "look_right",
+ "look_right",
+ "happy",
+ "closed",
+ "happy",
+ "happy",
+ ),
+ mouth=("rest", "rest", "closed", "closed", "smile", "closed", "smile", "smile"),
+ ),
+ _brew_pour_self_fx,
+ ),
+ IdleAct(
+ "whistle_tune",
+ 8,
+ 8,
+ _brew_act_pose(
+ "whistle_tune",
+ dx=(0, -1, 0, 1, 0, -1, 0, 0),
+ eyes=("open", "happy", "happy", "happy", "happy", "happy", "happy", "open"),
+ mouth=("rest", "o", "o", "o", "o", "o", "o", "rest"),
+ ),
+ _brew_whistle_fx,
+ ),
+ IdleAct(
+ "bubble_hiccup",
+ 8,
+ 10,
+ _brew_act_pose(
+ "bubble_hiccup",
+ dy=(0, -2, 0, 0, -3, 0, 0, 0),
+ stretch=(0, 1, -1, 0, 1, -1, 0, 0),
+ eyes=("open", "wide", "wide", "look_left", "wide", "wide", "closed", "open"),
+ mouth=("rest", "half", "closed", "closed", "open", "closed", "smile", "rest"),
+ ),
+ _brew_hiccup_fx,
+ ),
+)
+
+
BREW_ANCHORS = Anchors(
arcs_left=(11, 17),
arcs_right=(32, 17),
@@ -2159,6 +3163,7 @@ BREW = PetDesign(
pose=brew_pose,
anchors=BREW_ANCHORS,
post=brew_post,
+ acts=BREW_ACTS,
fx={
"idle": brew_idle,
"thinking": brew_thinking,
@@ -2318,6 +3323,8 @@ _BOLT_ARM_DROOP = rounded_rect(10, 28, 13, 33, 1)
def _bolt_arms(pose: Pose) -> tuple[Mask | None, Mask | None]:
"""The left and the right arm (``None``: drawn by the state's effect)."""
+ if pose.act:
+ return _bolt_act_arms(pose)
rest, up, swing = _BOLT_ARM_REST, _BOLT_ARM_UP, _BOLT_ARM_SWING
s, i = pose.state, pose.i
if s == "success":
@@ -2364,6 +3371,8 @@ def _bolt_glint(x0: int, segments: int) -> Mask:
def _bolt_charge(pose: Pose) -> dict[Px, RGBA]:
"""The charge window's contents for this pose."""
+ if pose.act:
+ return _bolt_act_charge(pose)
s, i = pose.state, pose.i
if s == "searching":
return _bolt_radar(i)
@@ -2482,6 +3491,8 @@ _BOLT_SLEEP_CABLE = _bolt_path([(4, 37), (4, 14), (5, 9), (8, 5), (13, 2), (20,
def draw_bolt(f: Frame, pose: Pose) -> None:
base, light, dark = BOLT_CASE_FLAT if pose.state == "sleeping" else BOLT_CASE
+ if pose.act == "power_surge" and pose.i == _BOLT_SURGE_FLASH:
+ base, light, dark = light, FX_WHITE, base # the white flash
with f.offset(pose.dx, pose.dy):
if pose.state == "sleeping":
_bolt_charger(f, pose.i)
@@ -2495,7 +3506,7 @@ def draw_bolt(f: Frame, pose: Pose) -> None:
_bolt_antenna(f, RED if pose.i % 2 == 0 else BOLT_RED_LIGHT)
cap = rounded_rect(19, 7, 28, 10, 1)
f.part(cap, _shade(cap, BOLT_METAL, FX_WHITE, BOLT_METAL_DARK, 1))
- if pose.state == "idle" and pose.i in (5, 6):
+ if pose.state == "idle" and pose.i in (5, 6) and not pose.act:
f.paint({(22 + pose.i - 5, 8)}, SPARK) # the terminal tingles
case = rounded_rect(13, 11, 34, 43, 2)
f.part(case, _shade(case, base, light, dark))
@@ -2705,30 +3716,382 @@ def bolt_held(f: Frame, pose: Pose) -> None:
f.paint(polyline(zig), ARC)
-BOLT_ANCHORS = Anchors(
- arcs_left=(12, 15),
- arcs_right=(35, 15),
- dots=(19, 2),
- zzz=(36, 14),
- bang=(38, 3),
- sweat=(35, 9),
- sparkles=((6, 10, 1), (41, 8, 2), (5, 36, 3), (42, 34, 3)),
+# -- Bolt's idle acts
+#
+# Little one-shot scenes between the breaths. The charge window plays along
+# in every one of them: it surges, drains, pulses, dances and runs a test.
+
+
+#: power_surge: the frame the whole casing flashes white.
+_BOLT_SURGE_FLASH = 3
+_BOLT_SURGE_POSES = (
+ Pose("idle", 0),
+ Pose("idle", 1, eyes="wide", mouth="half"),
+ Pose("idle", 2, dy=-1, eyes="wide", mouth="open", stretch=1),
+ Pose("idle", 3, dy=-2, eyes="happy", mouth="wide", stretch=1),
+ Pose("idle", 4, dy=-2, eyes="happy", mouth="wide", stretch=1),
+ Pose("idle", 5, dy=-1, eyes="happy", mouth="smile"),
+ Pose("idle", 6, eyes="happy", mouth="smile", stretch=-1),
+ Pose("idle", 7),
+)
+_BOLT_DRAIN_POSES = (
+ Pose("idle", 0),
+ Pose("idle", 1, eyes="down", mouth="closed"),
+ Pose("idle", 2, dy=1, eyes="sleep", mouth="frown", stretch=-1),
+ Pose("idle", 3, dy=1, eyes="sleep", mouth="half", stretch=-1),
+ Pose("idle", 4, dy=1, eyes="sleep", mouth="frown", stretch=-1),
+ Pose("idle", 5, dy=-1, eyes="wide", mouth="open", stretch=1),
+ Pose("idle", 6, dy=-1, eyes="happy", mouth="smile"),
+ Pose("idle", 7),
+)
+_BOLT_JUGGLE_POSES = (
+ Pose("idle", 0, eyes="up_right"),
+ Pose("idle", 1, eyes="look_left", mouth="closed"),
+ Pose("idle", 2, dy=-1, eyes="up_left", mouth="closed"),
+ Pose("idle", 3, eyes="up_right", mouth="closed"),
+ Pose("idle", 4, dy=-1, eyes="look_right", mouth="closed"),
+ Pose("idle", 5, eyes="up_left", mouth="closed"),
+ Pose("idle", 6, dy=-1, eyes="happy", mouth="smile"),
+ Pose("idle", 7, eyes="happy", mouth="smile"),
+)
+_BOLT_DANCE_POSES = (
+ Pose("idle", 0),
+ Pose("idle", 1, dx=-2, eyes="look_left", mouth="closed"),
+ Pose("idle", 2, dx=-2, dy=-1, eyes="open", mouth="closed"),
+ Pose("idle", 3, dx=2, eyes="look_right", mouth="closed"),
+ Pose("idle", 4, dx=2, dy=-1, eyes="open", mouth="closed"),
+ Pose("idle", 5, dy=-2, eyes="happy", mouth="smile", stretch=1),
+ Pose("idle", 6, dy=1, eyes="happy", mouth="smile", stretch=-1),
+ Pose("idle", 7),
+)
+_BOLT_CHECK_POSES = (
+ Pose("idle", 0),
+ Pose("idle", 1, eyes="up_right", mouth="closed"),
+ Pose("idle", 2, eyes="closed", mouth="closed"),
+ Pose("idle", 3, eyes="down", mouth="closed"),
+ Pose("idle", 4, eyes="down", mouth="closed"),
+ Pose("idle", 5, eyes="down", mouth="closed"),
+ Pose("idle", 6, eyes="happy", mouth="smile", stretch=1),
+ Pose("idle", 7, eyes="happy", mouth="smile"),
+)
+_BOLT_STATIC_POSES = (
+ Pose("idle", 0),
+ Pose("idle", 1, eyes="up_left", mouth="closed"),
+ Pose("idle", 2, eyes="up_right", mouth="closed"),
+ Pose("idle", 3, eyes="up_left", mouth="half", stretch=1),
+ Pose("idle", 4, eyes="wide", mouth="wide", stretch=1),
+ Pose("idle", 5, dx=-1, eyes="x", mouth="wide"),
+ Pose("idle", 6, dx=1, eyes="closed", mouth="frown"),
+ Pose("idle", 7, eyes="up_left", mouth="rest"),
)
-BOLT = PetDesign(
- id="bolt",
- name="Bolt",
- description="A plucky battery that charges up while it thinks and runs flat when it sleeps.",
- draw=draw_bolt,
- waist=23,
- anchors=BOLT_ANCHORS,
- pose=bolt_pose,
- frame_counts={"thinking": BOLT_THINK_FRAMES},
- fx={
- "idle": bolt_idle,
- "listening": bolt_listening,
- "thinking": bolt_thinking,
- "talking": bolt_talking,
+#: Arms per act frame: left then right; r rest, s swing, u up, d droop.
+_BOLT_ACT_ARMS: dict[str, tuple[str, ...]] = {
+ "power_surge": ("rr", "ss", "uu", "uu", "uu", "ss", "rr", "rr"),
+ "drain_flop": ("rr", "rr", "dd", "dd", "dd", "uu", "uu", "rr"),
+ "spark_juggle": ("rr", "sr", "rs", "sr", "rs", "sr", "uu", "rr"),
+ "robot_dance": ("rr", "ur", "ss", "ru", "ss", "uu", "rr", "rr"),
+ "self_check": ("rr", "rr", "rr", "rr", "rr", "rr", "ur", "rr"),
+ "static_hair": ("rr", "rr", "rr", "ss", "uu", "su", "us", "rr"),
+}
+_BOLT_ARM_CODES = {
+ "r": _BOLT_ARM_REST,
+ "s": _BOLT_ARM_SWING,
+ "u": _BOLT_ARM_UP,
+ "d": _BOLT_ARM_DROOP,
+}
+
+
+def _bolt_act_arms(pose: Pose) -> tuple[Mask, Mask]:
+ left, right = _BOLT_ACT_ARMS[pose.act][pose.i]
+ return _BOLT_ARM_CODES[left], mirrored(_BOLT_ARM_CODES[right])
+
+
+def _bolt_fill(level: int, color: RGBA) -> dict[Px, RGBA]:
+ out: dict[Px, RGBA] = {}
+ for k in range(level):
+ out.update(dict.fromkeys(_bolt_segment(k), color))
+ return out
+
+
+def _bolt_idle_charge() -> dict[Px, RGBA]:
+ return _bolt_fill(3, BOLT_GREEN)
+
+
+#: power_surge: segments lit per frame (5 = white-hot).
+_BOLT_SURGE_LEVELS = (3, 4, 5, 5, 5, 5, 4, 3)
+#: drain_flop: the charge per frame; negative = only a blinking red sliver.
+_BOLT_DRAIN_LEVELS = (3, 2, 1, 1, -1, 2, 4, 3)
+#: robot_dance: an equalizer, blocks lit per bar (four bars) per frame.
+_BOLT_EQ = (
+ (0, 0, 0, 0),
+ (2, 4, 3, 1),
+ (4, 2, 5, 3),
+ (3, 5, 2, 4),
+ (5, 3, 4, 2),
+ (2, 4, 5, 5),
+ (1, 2, 2, 1),
+ (0, 0, 0, 0),
+)
+#: static_hair: the charge climbs while static builds, then dumps it.
+_BOLT_STATIC_LEVELS = (3, 3, 4, 4, 5, 5, 2, 3)
+#: self_check: "OK" in the window (each letter 3 x 5, drawn 2x).
+_BOLT_OK = ("###.#.#", "#.#.#.#", "#.#.##.", "#.#.#.#", "###.#.#")
+
+
+def _bolt_eq(heights: Sequence[int]) -> dict[Px, RGBA]:
+ out: dict[Px, RGBA] = {}
+ for bar, height in enumerate(heights):
+ x = 18 + 3 * bar
+ for j in range(height):
+ color = BOLT_GREEN if j < 3 else SPARK if j == 3 else RED
+ if j == height - 1:
+ color = _bolt_light(color)
+ out.update(dict.fromkeys(rect(x, 39 - 3 * j, x + 2, 40 - 3 * j), color))
+ return out
+
+
+def _bolt_act_charge(pose: Pose) -> dict[Px, RGBA]:
+ """The charge window during an idle act."""
+ act, i = pose.act, pose.i
+ if act == "power_surge":
+ level = _BOLT_SURGE_LEVELS[i]
+ if level == 5:
+ return _bolt_fill(4, BOLT_GLOW)
+ out = _bolt_fill(level, BOLT_GREEN)
+ if i == 1: # the segment that just shot up
+ out.update(dict.fromkeys(_bolt_segment(3), BOLT_GREEN_LIGHT))
+ if i == 6:
+ out.update(dict.fromkeys(_bolt_glint(20, 4), BOLT_GREEN_LIGHT))
+ return out
+ if act == "drain_flop":
+ level = _BOLT_DRAIN_LEVELS[i]
+ if level < 0:
+ return {} # flat: the last sliver blinks off
+ out = _bolt_fill(level, _bolt_level_color(level))
+ if i >= 5: # recharging: the newest segment flashes
+ out.update(dict.fromkeys(_bolt_segment(level - 1), BOLT_GREEN_LIGHT))
+ return out
+ if act == "spark_juggle":
+ out = _bolt_idle_charge()
+ if 1 <= i <= 6: # every throw pulses up the window
+ out.update(dict.fromkeys(_bolt_segment(i % 3), BOLT_GREEN_LIGHT))
+ return out
+ if act == "robot_dance":
+ if i in (0, 7):
+ return _bolt_idle_charge()
+ return _bolt_eq(_BOLT_EQ[i])
+ if act == "self_check":
+ if i <= 2:
+ return _bolt_idle_charge()
+ if i <= 5: # testing the segments one by one from the bottom
+ tested = 2 * (i - 3) + 1
+ out = _bolt_fill(tested, BOLT_GREEN)
+ out.update(dict.fromkeys(_bolt_segment(tested - 1), BOLT_GLOW))
+ return out
+ if i == 6:
+ ok = from_rows(17, 28, [row for row in _BOLT_OK for _ in (0, 1)])
+ return {(17 + 2 * (x - 17) + dx, y): BOLT_GREEN for x, y in ok for dx in (0, 1)}
+ return _bolt_idle_charge()
+ if act == "static_hair":
+ level = _BOLT_STATIC_LEVELS[i]
+ if level == 5:
+ return _bolt_fill(4, BOLT_GLOW if i == 4 else BOLT_GREEN_LIGHT)
+ return _bolt_fill(level, _bolt_level_color(level))
+ return _bolt_idle_charge()
+
+
+#: The body's silhouette (cap, casing, resting arms) for the surge halo.
+_BOLT_SILHOUETTE = (
+ rounded_rect(13, 11, 34, 43, 2)
+ | rounded_rect(19, 7, 28, 10, 1)
+ | _BOLT_ARM_UP
+ | mirrored(_BOLT_ARM_UP)
+)
+#: Crackles around the body: zigzags that flicker on and off.
+_BOLT_CRACKLES = (
+ ((9, 13), (6, 15), (8, 17), (5, 19)),
+ ((38, 13), (41, 15), (39, 17), (42, 19)),
+ ((10, 36), (7, 38), (9, 40), (6, 42)),
+ ((37, 36), (40, 38), (38, 40), (41, 42)),
+)
+
+
+def bolt_power_surge(f: Frame, pose: Pose) -> None:
+ """The signature: the charge shoots to full and white-hot, the casing flashes
+ white, lightning crackles all around, then it settles back."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ if 2 <= i <= 4:
+ tint = {"#": SPARK_CORE if i == 3 else SPARK}
+ f.glyph(3, 9, _BOLT_GLYPH, tint)
+ f.glyph(41, 9, _BOLT_GLYPH, tint)
+ if i == _BOLT_SURGE_FLASH:
+ halo = outer_ring(_BOLT_SILHOUETTE | outer_ring(_BOLT_SILHOUETTE))
+ f.paint(_bolt_in_cell(halo), FX_WHITE)
+ if 3 <= i <= 5:
+ for k, zig in enumerate(_BOLT_CRACKLES):
+ if (k + i) % 2 == 0 or i == 3:
+ f.paint(polyline(zig), ARC if (k + i) % 2 == 0 else SPARK)
+ if i == 1:
+ f.glyph(23, 3, _BOLT_PLUS, _SPARK_PALETTE)
+ if i == 6:
+ f.glyph(15, 3, _BOLT_PLUS, _SPARK_PALETTE)
+ f.glyph(31, 4, _BOLT_PLUS, _SPARK_PALETTE)
+
+
+def bolt_drain_flop(f: Frame, pose: Pose) -> None:
+ """Running flat: a tired sigh puffs out, then a bolt zaps the cap and it
+ perks right back up."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ if i in (3, 4): # the sigh drifts off to the side
+ puff = ellipse(35 + 2 * (i - 3), 20 - (i - 3), 1.6 + 0.4 * (i - 3), 1.3)
+ _bolt_part(f, puff, BOLT_SMOKE if i == 3 else BOLT_SMOKE_LIGHT)
+ if i == 5:
+ f.glyph(22, 3, _BOLT_GLYPH, {"#": SPARK_CORE})
+ f.paint(polyline([(19, 8), (16, 6), (17, 5), (14, 3)]), ARC)
+ f.paint(polyline([(28, 8), (31, 6), (30, 5), (33, 3)]), ARC)
+ if i == 6:
+ f.glyph(13, 3, _BOLT_PLUS, _SPARK_PALETTE)
+ f.glyph(32, 3, _BOLT_PLUS, _SPARK_PALETTE)
+
+
+#: spark_juggle: the throw arc, from the left hand up over the cap to the
+#: right hand (the hand passes each spark back unseen, like a shower).
+def _bolt_juggle_at(t: float) -> Px:
+ u = t % 1.0
+ x = 7 + 33 * u
+ y = 21 - 18 * round(math.sin(math.pi * u), 6)
+ return math.floor(round(x, 6)), math.floor(round(y, 6))
+
+
+def bolt_spark_juggle(f: Frame, pose: Pose) -> None:
+ """Juggles three little sparks over its cap, then catches them in a sparkle."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ if i == 0:
+ f.glyph(23, 3, _BOLT_PLUS, _SPARK_PALETTE)
+ return
+ if i == 7:
+ fx_sparkles(f, 1, ((24, 3, 0),))
+ return
+ for k in range(3):
+ x, y = _bolt_juggle_at(0.05 + (i - 1) / 8 + k / 3)
+ palette = {"#": SPARK, "o": SPARK_CORE if k == 0 else ARC_FADE}
+ f.glyph(x - 1, y - 1, _BOLT_PLUS, palette)
+
+
+_BOLT_NOTE = (".##", ".#.", ".#.", "##.", "##.")
+
+
+def bolt_robot_dance(f: Frame, pose: Pose) -> None:
+ """A stiff robot dance: the charge bars bounce like an equalizer and little
+ notes pop out to the beat."""
+ i = pose.i
+ if not 1 <= i <= 6:
+ return
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ left = i % 2 == 1
+ x = 4 if left else 41
+ f.glyph(x, 12 - (i % 3), _BOLT_NOTE, {"#": FX_WHITE})
+ if i >= 4:
+ f.glyph(44 - x, 6 + (i % 2), _BOLT_NOTE, {"#": SPARK})
+
+
+#: self_check: the scan line's row per frame (None: no scan).
+_BOLT_SCAN_ROWS = (None, 8, 16, 26, 33, 40, None, None)
+_BOLT_TICK = ("......##", ".....##.", "##..##..", ".####...", "..##....")
+
+
+def bolt_self_check(f: Frame, pose: Pose) -> None:
+ """A diagnostic: a scan line sweeps down the body, the segments test one by
+ one, then "OK" lights up in the window with a tick beside it."""
+ i = pose.i
+ row = _BOLT_SCAN_ROWS[i]
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ if row is not None:
+ f.paint(rect(10, row, 37, row), ARC_FADE)
+ f.paint(rect(13, row, 34, row), FX_WHITE)
+ f.paint({(9, row), (38, row)}, ARC)
+ f.paint(rect(14, row - 1, 33, row - 1), ARC_FADE)
+ if i == 6:
+ f.glyph(37, 3, _BOLT_TICK, {"#": BOLT_GREEN})
+ elif i == 7:
+ fx_sparkles(f, 0, ((41, 5, 0),))
+
+
+#: static_hair: strand heights over the cap per frame (four strands).
+_BOLT_HAIR = (
+ (0, 0, 0, 0),
+ (1, 0, 2, 0),
+ (2, 3, 2, 1),
+ (3, 4, 4, 3),
+ (4, 5, 5, 4),
+ (4, 5, 5, 4),
+ (0, 0, 0, 0),
+ (0, 2, 0, 0),
+)
+_BOLT_HAIR_X = (19, 22, 25, 28)
+
+
+def bolt_static_hair(f: Frame, pose: Pose) -> None:
+ """Static builds up: little sparks stand up on the cap like hair, it shakes
+ them off with a zap, and one stubborn strand stays up."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy - pose.stretch):
+ strands: dict[Px, RGBA] = {}
+ for k, (x0, h) in enumerate(zip(_BOLT_HAIR_X, _BOLT_HAIR[i], strict=True)):
+ lean = -1 if k < 2 else 1
+ for r in range(h):
+ x = x0 + (lean if r >= 2 else 0) + (r % 2 if h >= 3 and r == h - 1 else 0)
+ strands[(x, 6 - r)] = SPARK_CORE if r == h - 1 else SPARK
+ if strands:
+ f.part(set(strands), strands)
+ if i == 4:
+ f.paint(polyline([(15, 5), (13, 4), (14, 3), (12, 2)]), ARC)
+ f.paint(polyline([(32, 5), (34, 4), (33, 3), (35, 2)]), ARC)
+ if i == 1:
+ f.paint({(24, 5), (21, 6), (27, 5)}, ARC)
+ if i == 6: # zap: the static jumps off both sides in a puff
+ fx_sparkles(f, 1, ((14, 4, 0), (34, 4, 0)))
+ _bolt_part(f, ellipse(24, 3, 2.6, 1.8), BOLT_SMOKE_LIGHT)
+
+
+BOLT_ACTS = (
+ IdleAct("power_surge", 8, 10, lambda i: _BOLT_SURGE_POSES[i], bolt_power_surge),
+ IdleAct("drain_flop", 8, 8, lambda i: _BOLT_DRAIN_POSES[i], bolt_drain_flop),
+ IdleAct("spark_juggle", 8, 8, lambda i: _BOLT_JUGGLE_POSES[i], bolt_spark_juggle),
+ IdleAct("robot_dance", 8, 8, lambda i: _BOLT_DANCE_POSES[i], bolt_robot_dance),
+ IdleAct("self_check", 8, 7, lambda i: _BOLT_CHECK_POSES[i], bolt_self_check),
+ IdleAct("static_hair", 8, 8, lambda i: _BOLT_STATIC_POSES[i], bolt_static_hair),
+)
+
+
+BOLT_ANCHORS = Anchors(
+ arcs_left=(12, 15),
+ arcs_right=(35, 15),
+ dots=(19, 2),
+ zzz=(36, 14),
+ bang=(38, 3),
+ sweat=(35, 9),
+ sparkles=((6, 10, 1), (41, 8, 2), (5, 36, 3), (42, 34, 3)),
+)
+
+BOLT = PetDesign(
+ id="bolt",
+ name="Bolt",
+ description="A plucky battery that charges up while it thinks and runs flat when it sleeps.",
+ draw=draw_bolt,
+ waist=23,
+ anchors=BOLT_ANCHORS,
+ pose=bolt_pose,
+ frame_counts={"thinking": BOLT_THINK_FRAMES},
+ fx={
+ "idle": bolt_idle,
+ "listening": bolt_listening,
+ "thinking": bolt_thinking,
+ "talking": bolt_talking,
"success": bolt_success,
"error": bolt_error,
"sleeping": bolt_sleeping,
@@ -2736,6 +4099,7 @@ BOLT = PetDesign(
"searching": bolt_searching,
"held": bolt_held,
},
+ acts=BOLT_ACTS,
)
@@ -2862,6 +4226,9 @@ def _mochi_top(body: Mask, x: int) -> int:
def draw_mochi(f: Frame, pose: Pose) -> None:
+ if pose.act:
+ _draw_mochi_act(f, pose)
+ return
if pose.state == "held":
_draw_mochi_dough(f, pose)
return
@@ -3149,6 +4516,419 @@ def mochi_listening(f: Frame, pose: Pose) -> None:
f.paint({(x + off + ax, y + pose.dy + ay) for ax, ay in arc}, ARC_FADE if fading else ARC)
+# -- Mochi's idle acts ----------------------------------------------------------
+#
+# Little scenes Mochi plays while nothing happens. Each act draws its own body
+# (``_draw_mochi_act``) through the same jelly paint and face as the states.
+
+#: The two mini mochis' eyes in the split act.
+MOCHI_MINI_EYES = EyeStyle(w=2, h=3, iris=MOCHI_INK, glint=FX_WHITE, lid=MOCHI_INK)
+#: The shadow under an airborne Mochi (opaque; a soft mauve that holds on both desktops).
+MOCHI_SHADOW = hexc("#6b5470")
+#: Glossy spot on the dome's top-left, before the ``lower`` shift.
+_MOCHI_GLINT = frozenset({(15, 25), (16, 24), (17, 24), (14, 26)})
+
+#: big_bounce: (wider, lower, dy, eyes, mouth) — squash, launch, a tall
+#: stretch, round at the top, falling, a splat, settling.
+_MOCHI_BOUNCE = (
+ (0, 0, 0, "open", "rest"),
+ (3, 3, 0, "closed", "closed"),
+ (-3, -4, -6, "wide", "open"),
+ (-1, -2, -12, "happy", "open"),
+ (0, -1, -14, "happy", "wide"),
+ (-2, -3, -8, "wide", "half"),
+ (5, 4, 0, "closed", "closed"),
+ (1, 1, 0, "happy", "smile"),
+)
+#: split_merge: eyes and mouth per frame; frames 0, 1 and 7 are one blob
+#: (wider, lower), the others two minis.
+_MOCHI_SPLIT_FACE = (
+ ("open", "rest"),
+ ("closed", "closed"),
+ ("closed", "closed"),
+ ("open", "rest"),
+ ("happy", "smile"),
+ ("happy", "smile"),
+ ("wide", "rest"),
+ ("happy", "smile"),
+)
+_MOCHI_SPLIT_BLOB = {0: (0, 0), 1: (4, 1), 7: (1, 1)}
+#: The minis per frame: (cx, dy, wider, lower) each — pinched apart, split,
+#: hopping in turn, jumping back together.
+_MOCHI_MINIS: dict[int, tuple[tuple[int, int, int, int], ...]] = {
+ 2: ((17, 0, 0, 0), (31, 0, 0, 0)),
+ 3: ((13, 0, 1, 1), (35, 0, 1, 1)),
+ 4: ((13, -6, -1, -1), (35, 0, 1, 1)),
+ 5: ((13, 0, 1, 1), (35, -6, -1, -1)),
+ 6: ((18, -4, 0, 0), (30, -4, 0, 0)),
+}
+#: bubble_blow: (wider, lower, eyes, mouth, bubble radius) — a breath in,
+#: puffed cheeks, the bubble swells, pops in Mochi's face, a happy grin.
+_MOCHI_BLOW = (
+ (0, 0, "open", "rest", 0.0),
+ (-1, -1, "closed", "closed", 0.0),
+ (1, 0, "closed", "pucker", 2.0),
+ (1, 0, "closed", "pucker", 3.5),
+ (1, 0, "up_right", "pucker", 5.0),
+ (1, 0, "wide", "pucker", 6.5),
+ (2, 2, "closed", "open", 0.0),
+ (0, 0, "happy", "smile", 0.0),
+)
+#: shape_shift: (shape, eyes, mouth) — gather, a star, a heart, back to a blob.
+_MOCHI_SHIFT = (
+ ("blob", "open", "rest"),
+ ("squash", "closed", "closed"),
+ ("star", "wide", "open"),
+ ("star", "happy", "smile"),
+ ("heart", "open", "smile"),
+ ("heart", "happy", "smile"),
+ ("squash", "closed", "rest"),
+ ("blob", "open", "smile"),
+)
+#: melt_reform: (shape, wider, lower, dy, eyes, mouth) — Mochi melts happily
+#: into a puddle, peeks out, springs back up with a boing and settles.
+_MOCHI_MELT_ACT = (
+ ("blob", 0, 0, 0, "open", "rest"),
+ ("blob", 2, 2, 0, "sleep", "smile"),
+ ("blob", 5, 5, 0, "sleep", "smile"),
+ ("puddle", 0, 0, 0, "closed", "closed"),
+ ("ripple", 0, 0, 0, "open", "closed"),
+ ("blob", -4, -5, -3, "wide", "open"),
+ ("blob", 3, 3, 0, "happy", "smile"),
+ ("blob", 0, 0, 0, "open", "smile"),
+)
+#: wiggle_dance: (sway, dx, dy, wider, lower, eyes, mouth, raised nub) — the
+#: dome swings left and right, one nub up on the side it leans to.
+_MOCHI_DANCE = (
+ (0, 0, 0, 0, 0, "open", "rest", 0),
+ (-2, -1, 0, 1, 1, "happy", "smile", -1),
+ (-3, -2, -1, 0, -1, "happy", "open", -1),
+ (0, 0, 0, 1, 1, "happy", "smile", 0),
+ (2, 1, 0, 1, 1, "happy", "smile", 1),
+ (3, 2, -1, 0, -1, "happy", "open", 1),
+ (0, 0, 0, 1, 1, "happy", "smile", 0),
+ (0, 0, 0, 0, 0, "open", "smile", 0),
+)
+#: wiggle_dance: where the music notes float per frame (top-left, colour),
+#: one rising on each side in turn.
+_MOCHI_NOTES = {
+ 1: ((4, 12, 0),),
+ 2: ((3, 8, 0),),
+ 3: ((4, 4, 0), (38, 12, 1)),
+ 4: ((5, 1, 0), (39, 8, 1)),
+ 5: ((39, 4, 1),),
+ 6: ((38, 1, 1),),
+}
+_MOCHI_NOTE = ("..##.", "..#.#", "..#..", "###..", "###..")
+_MOCHI_HEART = ("#.#", "###", ".#.")
+
+
+def _mochi_act_pose(name: str, rows: Sequence[tuple[int, int, str, str]]) -> Callable[[int], Pose]:
+ """An act's pose function from (dx, dy, eyes, mouth) rows."""
+
+ def pose(i: int) -> Pose:
+ dx, dy, eyes, mouth = rows[i]
+ return Pose("idle", i, dx=dx, dy=dy, eyes=eyes, mouth=mouth, act=name)
+
+ return pose
+
+
+def _mochi_act_face(f: Frame, pose: Pose, eye_y: int, dx: int, inner: Mask) -> None:
+ """The usual face, with the blush kept on the jelly and a puckered "o" mouth."""
+ draw_eyes(f, pose.eyes, (17 + dx, eye_y), (28 + dx, eye_y), MOCHI_EYES)
+ blush = rect(13 + dx, eye_y + 4, 15 + dx, eye_y + 4)
+ f.paint((blush | shifted(mirrored(blush), 2 * dx, 0)) & inner, MOCHI_BLUSH)
+ if pose.mouth == "pucker":
+ f.paint(from_rows(22 + dx, eye_y + 5, (".##.", "#..#", ".##.")), MOCHI_INK)
+ else:
+ draw_mouth(f, pose.mouth, 22 + dx, eye_y + 5, 4, color=MOCHI_INK)
+
+
+def _mochi_jelly(
+ f: Frame, pose: Pose, body: Mask, eye_y: int, face_dx: int = 0, glint: Iterable[Px] = ()
+) -> None:
+ _mochi_paint_body(f, body)
+ inner = eroded(body, 1)
+ f.paint(set(glint) & inner, FX_WHITE)
+ _mochi_act_face(f, pose, eye_y, face_dx, inner)
+
+
+def _mochi_act_blob(
+ f: Frame,
+ pose: Pose,
+ wider: int,
+ lower: int,
+ sway: int = 0,
+ face_dx: int = 0,
+ extra: Mask | None = None,
+) -> None:
+ """The ordinary blob, squashed or stretched; a squash stays on the ground."""
+ plant = max(0, lower - 1)
+ body = shifted(_mochi_body(wider, lower, sway), 0, plant) | (extra or set())
+ glint = shifted(_MOCHI_GLINT, 0, lower + plant)
+ _mochi_jelly(f, pose, body, 30 + max(0, lower) // 2 + plant, face_dx, glint)
+
+
+def _mochi_puff(f: Frame, x: int, y: int, big: bool) -> None:
+ """A little dust cloud kicked up on landing."""
+ cloud = ellipse(x + 0.5, y + 0.5, 2.6 if big else 1.7, 1.8 if big else 1.2)
+ bottom = max(py for _, py in cloud)
+ f.part(cloud, {p: (FX_DIM if p[1] == bottom else FX_WHITE) for p in cloud})
+
+
+def _mochi_bounce_pose(i: int) -> Pose:
+ _, _, dy, eyes, mouth = _MOCHI_BOUNCE[i]
+ return Pose("idle", i, dy=dy, eyes=eyes, mouth=mouth, act="big_bounce")
+
+
+def _mochi_act_bounce(f: Frame, pose: Pose) -> None:
+ wider, lower, *_ = _MOCHI_BOUNCE[pose.i]
+ _mochi_act_blob(f, pose, wider, lower)
+
+
+def mochi_act_big_bounce(f: Frame, pose: Pose) -> None:
+ """A shadow that shrinks as Mochi flies, speed lines on take-off, a sparkle
+ at the top and dust puffs and boing marks on the splat."""
+ i, dy = pose.i, pose.dy
+ if dy < 0:
+ f.paint(ellipse(CX, 45.5, 11 + dy // 3, 1.3), MOCHI_SHADOW)
+ if i in (2, 3):
+ for x in (17, 30):
+ f.paint(line(x, 45 + dy, x, 47 + dy - (i - 2)), ARC_FADE)
+ if i == 4:
+ fx_sparkles(f, 1, ((39, 8, 0),))
+ if i == 5:
+ fx_sparkles(f, 0, ((39, 8, 0),))
+ if i == 6:
+ _mochi_puff(f, 4, 41, True)
+ _mochi_puff(f, 42, 41, True)
+ f.paint(line(2, 30, 2, 36) | line(45, 30, 45, 36), ARC)
+ if i == 7:
+ _mochi_puff(f, 3, 38, False)
+ _mochi_puff(f, 43, 38, False)
+
+
+def _mochi_mini_body(cx: int, wider: int, lower: int) -> Mask:
+ """A mini mochi half the size, its bottom on the ground."""
+ plant = max(0, lower - 1)
+ blob = {p for p in ellipse(cx, 37.5, 8.5 + wider, 7 - lower) if p[1] <= 43}
+ dome = ellipse(cx, 34 + lower, 6 + max(0, wider), 5.5)
+ return shifted(blob | dome, 0, plant)
+
+
+def _mochi_act_split(f: Frame, pose: Pose) -> None:
+ i = pose.i
+ if i in _MOCHI_SPLIT_BLOB:
+ _mochi_act_blob(f, pose, *_MOCHI_SPLIT_BLOB[i])
+ return
+ minis = _MOCHI_MINIS[i]
+ body: Mask = set()
+ for cx, dy, wider, lower in minis:
+ body |= shifted(_mochi_mini_body(cx, wider, lower), 0, dy)
+ if i == 2:
+ # Still joined: a thin jelly bridge before they snap apart.
+ body |= rect(21, 37, 26, 41)
+ _mochi_paint_body(f, body)
+ inner = eroded(body, 1)
+ for cx, dy, _, lower in minis:
+ y = 34 + dy + max(0, lower - 1) + max(0, lower) // 2
+ f.paint({(cx - 5, y - 2), (cx - 4, y - 3)} & inner, FX_WHITE)
+ draw_eyes(f, pose.eyes, (cx - 4, y), (cx + 2, y), MOCHI_MINI_EYES)
+ f.paint({(cx - 6, y + 3), (cx + 5, y + 3)} & inner, MOCHI_BLUSH)
+ draw_mouth(f, pose.mouth, cx - 2, y + 4, 4, color=MOCHI_INK)
+
+
+def mochi_act_split_merge(f: Frame, pose: Pose) -> None:
+ """A pop where the jelly snaps in two, hop streaks under each jumper and
+ a pair of sparkles when the minis plop back into one Mochi."""
+ i = pose.i
+ if i == 3:
+ f.paint({(24, 30), (23, 30), (20, 32), (27, 32), (19, 35), (28, 35)}, ARC)
+ for hopper, frame in ((13, 4), (35, 5)):
+ if i == frame:
+ streaks = line(hopper - 3, 39, hopper - 3, 41) | line(hopper + 2, 39, hopper + 2, 41)
+ f.paint(streaks, ARC_FADE)
+ if i == 6:
+ f.paint(line(4, 30, 7, 30) | line(40, 30, 43, 30), ARC_FADE)
+ if i == 7:
+ fx_sparkles(f, 1, ((5, 26, 0), (42, 26, 0)))
+
+
+def _mochi_blow_pose(i: int) -> Pose:
+ _, _, eyes, mouth, _ = _MOCHI_BLOW[i]
+ return Pose("idle", i, eyes=eyes, mouth=mouth, act="bubble_blow")
+
+
+def _mochi_act_blow(f: Frame, pose: Pose) -> None:
+ wider, lower, *_ = _MOCHI_BLOW[pose.i]
+ _mochi_act_blob(f, pose, wider, lower)
+
+
+def _mochi_blow_centre(r: float) -> tuple[float, float]:
+ """The bubble grows out of the puckered mouth towards the upper right."""
+ return 26.0 + r, 36.0 - r
+
+
+def mochi_act_bubble_blow(f: Frame, pose: Pose) -> None:
+ """A see-through soap bubble swelling from the mouth; it pops into
+ streaks and a few drops."""
+ i = pose.i
+ r = _MOCHI_BLOW[i][4]
+ if r:
+ cx, cy = _mochi_blow_centre(r)
+ disc = ellipse(cx, cy, r, r)
+ ring = disc - eroded(disc, 1)
+ f.paint(outer_ring(disc), OUTLINE)
+ f.paint(ring, SWEAT)
+ top = min(y for _, y in ring)
+ f.paint({p for p in ring if p[1] <= top + 1 and p[0] < cx - 1}, FX_WHITE)
+ return
+ cx, cy = _mochi_blow_centre(6.5)
+ if i == 6:
+ for k in range(8):
+ angle = 2.0 * math.pi * k / 8
+ c, s = round(math.cos(angle), 6), round(math.sin(angle), 6)
+ a = (math.floor(cx + c * 6.5), math.floor(cy + s * 6.5))
+ b = (math.floor(cx + c * 9.0), math.floor(cy + s * 9.0))
+ f.paint(line(*a, *b), ARC if k % 2 else ARC_FADE)
+ if i == 7:
+ for x, y in ((30, 23), (39, 27), (35, 20)):
+ f.part({(x, y)}, SWEAT)
+
+
+def _mochi_star() -> Mask:
+ """A chubby five-pointed star centred on the face."""
+ points = []
+ for k in range(10):
+ angle = -math.pi / 2 + k * math.pi / 5
+ r = 17.0 if k % 2 == 0 else 10.5
+ points.append((CX + round(math.cos(angle) * r, 6), 30 + round(math.sin(angle) * r, 6)))
+ return polygon(points)
+
+
+def _mochi_heart() -> Mask:
+ lobes = ellipse(CX - 6, 28, 7.5, 7) | ellipse(CX + 6, 28, 7.5, 7)
+ return lobes | polygon([(CX - 13.4, 30), (CX + 13.4, 30), (CX, 44)])
+
+
+def _mochi_shift_pose(i: int) -> Pose:
+ _, eyes, mouth = _MOCHI_SHIFT[i]
+ return Pose("idle", i, eyes=eyes, mouth=mouth, act="shape_shift")
+
+
+def _mochi_act_shift(f: Frame, pose: Pose) -> None:
+ shape = _MOCHI_SHIFT[pose.i][0]
+ if shape == "star":
+ _mochi_jelly(f, pose, _mochi_star(), 28, glint={(22, 19), (22, 20), (23, 18)})
+ elif shape == "heart":
+ _mochi_jelly(f, pose, _mochi_heart(), 29, glint={(13, 26), (14, 25), (15, 24), (16, 24)})
+ else:
+ _mochi_act_blob(f, pose, *((2, 2) if shape == "squash" else (0, 0)))
+
+
+def mochi_act_shape_shift(f: Frame, pose: Pose) -> None:
+ """Sparkles while Mochi is a star, little hearts floating up from the heart."""
+ i = pose.i
+ if i == 2:
+ fx_sparkles(f, 1, ((5, 10, 0),))
+ if i == 3:
+ fx_sparkles(f, 1, ((42, 9, 0),))
+ fx_sparkles(f, 0, ((5, 10, 0),))
+ hearts = {4: ((38, 19),), 5: ((39, 14), (6, 20)), 6: ((40, 9), (5, 15))}
+ for x, y in hearts.get(i, ()):
+ f.glyph(x, y, _MOCHI_HEART, {"#": MOCHI_BLUSH})
+
+
+def _mochi_melt_pose(i: int) -> Pose:
+ _, _, _, dy, eyes, mouth = _MOCHI_MELT_ACT[i]
+ return Pose("idle", i, dy=dy, eyes=eyes, mouth=mouth, act="melt_reform")
+
+
+def _mochi_act_melt(f: Frame, pose: Pose) -> None:
+ shape, wider, lower, *_ = _MOCHI_MELT_ACT[pose.i]
+ if shape == "blob":
+ _mochi_act_blob(f, pose, wider, lower)
+ return
+ puddle = {p for p in ellipse(CX, 40.5, 20, 4.5) if p[1] <= 44}
+ if shape == "ripple":
+ # The jelly gathers in the middle before it springs back up.
+ puddle |= ellipse(CX, 38.5, 8, 3.5)
+ _mochi_jelly(f, pose, puddle, 36, glint={(10, 38), (11, 38), (12, 37)})
+
+
+def mochi_act_melt_reform(f: Frame, pose: Pose) -> None:
+ """Ripples beside the puddle, a spring coil and boing marks as Mochi
+ shoots back up, dust puffs on landing."""
+ i = pose.i
+ if i == 3:
+ f.paint(line(1, 39, 1, 42) | line(46, 39, 46, 42), ARC_FADE)
+ if i == 4:
+ f.paint(line(0, 38, 0, 43) | line(47, 38, 47, 43), ARC_FADE)
+ if i == 5:
+ f.paint(polyline(((19, 42), (28, 43), (19, 44), (28, 45), (19, 46))), ARC)
+ f.paint(line(6, 22, 6, 32) | line(41, 22, 41, 32), ARC)
+ f.paint(line(3, 25, 3, 29) | line(44, 25, 44, 29), ARC_FADE)
+ if i == 6:
+ _mochi_puff(f, 4, 41, True)
+ _mochi_puff(f, 42, 41, True)
+
+
+def _mochi_dance_pose(i: int) -> Pose:
+ _, dx, dy, _, _, eyes, mouth, _ = _MOCHI_DANCE[i]
+ return Pose("idle", i, dx=dx, dy=dy, eyes=eyes, mouth=mouth, act="wiggle_dance")
+
+
+def _mochi_nub(up: bool) -> Mask:
+ """A left jelly nub: raised to wave, or resting against the side."""
+ if up:
+ return _mochi_capsule((11, 31), (6, 23), 1.6) | ellipse(6.0, 22.5, 2.2, 2.2)
+ return ellipse(9.0, 36.5, 2.4, 2.2)
+
+
+def _mochi_act_dance(f: Frame, pose: Pose) -> None:
+ sway, _, _, wider, lower, _, _, raised = _MOCHI_DANCE[pose.i]
+ nubs = _mochi_nub(raised < 0) | mirrored(_mochi_nub(raised > 0))
+ _mochi_act_blob(f, pose, wider, lower, sway, int(sway * 2 / 3), nubs)
+
+
+def mochi_act_wiggle_dance(f: Frame, pose: Pose) -> None:
+ """Music notes floating up on either side while Mochi dances."""
+ for x, y, color in _MOCHI_NOTES.get(pose.i, ()):
+ f.glyph(x, y, _MOCHI_NOTE, {"#": ARC if color == 0 else MOCHI_BLUSH})
+
+
+#: Each act's body drawing, by name.
+_MOCHI_ACT_DRAW: dict[str, Effect] = {
+ "big_bounce": _mochi_act_bounce,
+ "split_merge": _mochi_act_split,
+ "bubble_blow": _mochi_act_blow,
+ "shape_shift": _mochi_act_shift,
+ "melt_reform": _mochi_act_melt,
+ "wiggle_dance": _mochi_act_dance,
+}
+
+
+def _draw_mochi_act(f: Frame, pose: Pose) -> None:
+ with f.offset(pose.dx, pose.dy):
+ _MOCHI_ACT_DRAW[pose.act](f, pose)
+
+
+MOCHI_ACTS = (
+ IdleAct("big_bounce", 8, 10, _mochi_bounce_pose, mochi_act_big_bounce),
+ IdleAct(
+ "split_merge",
+ 8,
+ 8,
+ _mochi_act_pose("split_merge", [(0, 0, e, m) for e, m in _MOCHI_SPLIT_FACE]),
+ mochi_act_split_merge,
+ ),
+ IdleAct("bubble_blow", 8, 8, _mochi_blow_pose, mochi_act_bubble_blow),
+ IdleAct("shape_shift", 8, 8, _mochi_shift_pose, mochi_act_shape_shift),
+ IdleAct("melt_reform", 8, 8, _mochi_melt_pose, mochi_act_melt_reform),
+ IdleAct("wiggle_dance", 8, 8, _mochi_dance_pose, mochi_act_wiggle_dance),
+)
+
+
MOCHI = PetDesign(
id="mochi",
name="Mochi",
@@ -3168,6 +4948,7 @@ MOCHI = PetDesign(
"searching": mochi_searching,
"held": mochi_held,
},
+ acts=MOCHI_ACTS,
)
@@ -3368,6 +5149,9 @@ def _shelly_phase(pose: Pose) -> float:
def draw_shelly(f: Frame, pose: Pose) -> None:
+ if pose.act:
+ _draw_shelly_act(f, pose)
+ return
if pose.state == "sleeping":
_draw_shelly_withdrawn(f, pose)
return
@@ -3614,591 +5398,334 @@ def _shelly_held_fx(f: Frame, pose: Pose) -> None:
f.glyph(5 - k, 30 + 2 * k, (".#.", "###", "#o#", ".#."), {"#": SWEAT, "o": SWEAT_SHINE})
-SHELLY = PetDesign(
- id="shelly",
- name="Shelly",
- description="A patient snail whose shell spins while it thinks and who hides inside to sleep.",
- draw=draw_shelly,
- pose=shelly_pose,
- waist=38,
- anchors=Anchors(
- arcs_left=(8, 6),
- arcs_right=(21, 7),
- dots=(27, 8),
- zzz=(35, 15),
- bang=(40, 4),
- sweat=(17, 24),
- sparkles=((3, 26, 1), (41, 10, 2), (3, 40, 3), (44, 28, 3)),
- ),
- fx={
- "idle": _shelly_idle_fx,
- "listening": _shelly_listening_fx,
- "thinking": _shelly_thinking_fx,
- "talking": _shelly_talking_fx,
- "success": _shelly_success_fx,
- "working": _shelly_laptop_fx,
- "searching": _shelly_searching_fx,
- "held": _shelly_held_fx,
- },
+# Shelly's idle acts. Each act is a table of stalk tips, looks and a mouth
+# per frame, drawn through the same parts as the idle snail; the act's effect
+# layer adds the props (a leaf, a rag, a raindrop) and keeps the slime trail.
+
+SHELLY_LEAF = hexc("#5cb84a")
+SHELLY_LEAF_DARK = hexc("#357a2c")
+SHELLY_RAG = hexc("#8fb4ff")
+SHELLY_RAG_LIGHT = hexc("#d6e4ff")
+
+#: One act frame: (left tip, right tip, left look, right look, mouth); ``None``
+#: means Shelly is tucked into the shell for that frame.
+_ShellyActFrame = tuple[Px, Px, str, str, str] | None
+
+_REST_L, _REST_R = _SHELLY_TIPS["rest"]
+
+#: Hide and seek: the stalks pull in, Shelly vanishes into the shell, one
+#: stalk peeks out of the opening and looks around, then the head comes back.
+_SHELLY_PEEK_HIDE: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((10, 21), (15, 21), "closed", "closed", "closed"),
+ None,
+ None,
+ None,
+ None,
+ ((9, 19), (15, 18), "look_right", "look_right", "smile"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
)
-
-
-# -- Pip: the baby -----------------------------------------------------------------
-#
-# A chubby baby in a butter-yellow onesie: a big round head with a single curl
-# of hair on top, rosy cheeks, dark shiny eyes and a pink pacifier that does
-# half the acting. Pip sucks it while idling, lets it drop to listen, chews a
-# rattle while thinking, babbles, claps, cries, naps under a mint blanket,
-# bangs a toy keyboard, peers through a toy magnifier and kicks with delight
-# when it is picked up.
-
-PIP_SKIN = hexc("#ffd3b4")
-PIP_SKIN_LIGHT = hexc("#ffe9d8")
-PIP_SKIN_DARK = hexc("#e9a684")
-PIP_SUIT = hexc("#ffdc6a")
-PIP_SUIT_LIGHT = hexc("#fff2b0")
-PIP_SUIT_DARK = hexc("#e0a93a")
-PIP_MINT = hexc("#5fcfa6")
-PIP_MINT_LIGHT = hexc("#a9ecd2")
-PIP_MINT_DARK = hexc("#3a9e7c")
-PIP_HAIR = hexc("#a9683a")
-PIP_EYE = hexc("#2b2133")
-PIP_PACI = hexc("#ff8ab4")
-PIP_PACI_LIGHT = hexc("#ffc6dc")
-PIP_PACI_RING = hexc("#6cc4ff")
-#: Crying: the cheeks flush a deeper pink.
-PIP_FLUSH = hexc("#ff6f86")
-PIP_PILLOW = hexc("#eef0fb")
-PIP_PILLOW_DARK = hexc("#c3c8de")
-#: The toy keyboard's case, and the colours of its keys, the confetti and
-#: the rattle: one bright nursery set.
-PIP_TOY = (hexc("#5aa9ff"), hexc("#9ccbff"), hexc("#3b7fd0"))
-PIP_TOYS = (hexc("#ff6b6b"), hexc("#ffd23f"), hexc("#5fcfa6"), hexc("#c58bff"), hexc("#ff8ab4"))
-PIP_HEART = hexc("#ff6f91")
-PIP_HEART_SHINE = hexc("#ffd3de")
-
-#: The top-left of each 4 x 5 eye; looks move the whole eye a pixel.
-_PIP_EYE_AT: tuple[Px, Px] = ((16, 16), (28, 16))
-_PIP_LOOK: dict[str, Px] = {
- "open": (0, 0),
- "wide": (0, 0),
- "look_left": (-1, 0),
- "look_right": (1, 0),
- "up_left": (-1, -1),
- "up_right": (1, -1),
- "down": (0, 1),
-}
-#: Closed-eye shapes on the 4 x 5 eye box: content, happy and a scrunched cry.
-_PIP_LIDS: dict[str, tuple[str, ...]] = {
- "closed": ("....", "....", "#..#", ".##.", "...."),
- "sleep": ("....", "....", "#..#", ".##.", "...."),
- "happy": ("....", ".##.", "#..#", "....", "...."),
- "cry": ("#...", ".##.", "...#", ".##.", "#..."),
+#: The peeking stalk while tucked in: (tip, look) per frame, or nothing.
+_SHELLY_PEEK_STALK: dict[int, tuple[Px, str] | None] = {
+ 2: None,
+ 3: ((16, 34), "closed"),
+ 4: ((13, 30), "look_left"),
+ 5: ((14, 29), "look_right"),
}
-_PIP_STAR = ("..#..", ".###.", "#####", ".###.", ".#.#.")
-
-#: Idle: where Pip looks over the seven breathing cells, the suck of the
-#: pacifier (1 = drawn in) and which foot wiggles (left, right lift).
-_PIP_IDLE_LOOK = ("open", "open", "look_left", "look_left", "open", "look_right", "open")
-_PIP_SUCK = (0, 1, 0, 1, 0, 0, 1)
-_PIP_IDLE_KICK = ((0, 0), (0, 0), (1, 0), (0, 0), (0, 0), (0, 1), (0, 0))
-#: Listening: the head tilts towards the cupped hand and back.
-_PIP_TILT = (0, 1, 1, 1, 1, 0)
-#: Success: a bounce on the bottom (a sitting baby hops lower than the
-#: others, so the curl stays in the cell) and the stretch that goes with it.
-_PIP_HOP = (0, -1, -2, -3, -2, -1, 0, 0)
-#: Success: hands together on every other frame of the hop.
-_PIP_CLAP = (False, True, False, True, False, True, False, False)
-#: Working: which key each hand bangs per frame (None = lifted); left hand
-#: plays the two left keys, right hand the two right ones.
-_PIP_BANG: tuple[tuple[int | None, int | None], ...] = (
- (0, None),
- (None, 4),
- (1, None),
- (None, None),
- (None, 3),
- (0, 4),
- (None, 3),
- (None, None),
+#: Munching a leaf: lean in, chomp twice, a happy swallow.
+_SHELLY_LEAF_MUNCH: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((7, 16), (16, 15), "down_left", "down_left", "rest"),
+ ((7, 17), (15, 16), "down_left", "down_left", "open"),
+ ((7, 17), (15, 16), "closed", "closed", "closed"),
+ ((7, 17), (15, 16), "down_left", "down_left", "open"),
+ ((7, 17), (15, 16), "closed", "closed", "closed"),
+ ((8, 15), (17, 14), "happy", "happy", "smile"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
)
-#: Held: the swing from the cursor and the kicking feet (left, right lift).
-_PIP_SWAY = (-1, 0, 1, 1, 0, -1)
-_PIP_HELD_KICK = ((3, 0), (1, 1), (0, 3), (0, 2), (1, 1), (2, 0))
-
-
-def pip_pose(state: str, i: int) -> Pose:
- pose = base_pose(state, i)
- if state == "idle":
- look = _PIP_IDLE_LOOK[i] if i < len(_PIP_IDLE_LOOK) else pose.eyes
- return replace(pose, eyes=look, mouth="paci")
- if state == "listening":
- return replace(pose, mouth="o")
- if state == "thinking":
- return replace(pose, mouth="chew")
- if state == "success":
- return replace(pose, dy=_PIP_HOP[i], mouth="grin")
- if state == "error":
- return replace(pose, eyes="cry", mouth="wail")
- if state == "sleeping":
- # Lying down: the blanket does the breathing, not a body stretch.
- return Pose(state, i, eyes="sleep", mouth="paci")
- if state == "working":
- return replace(pose, mouth="paci")
- if state == "searching":
- sweep = SEARCH_SWEEP[i % len(SEARCH_SWEEP)]
- lean = (sweep > 2) - (sweep < -2)
- return Pose(state, i, dx=lean, eyes=SEARCH_EYES[i], mouth="o")
- if state == "held":
- return Pose(state, i, dx=_PIP_SWAY[i % len(_PIP_SWAY)], eyes="happy", mouth="grin")
- return pose
-
-
-def _pip_skin(f: Frame, mask: Mask, depth: int = 1) -> None:
- f.part(mask, _shade(mask, PIP_SKIN, PIP_SKIN_LIGHT, PIP_SKIN_DARK, depth))
-
-
-def _pip_suit(f: Frame, mask: Mask, depth: int = 2) -> None:
- f.part(mask, _shade(mask, PIP_SUIT, PIP_SUIT_LIGHT, PIP_SUIT_DARK, depth))
-
-
-def _pip_hand(f: Frame, x: float, y: float, r: float = 2.2) -> None:
- _pip_skin(f, ellipse(x + 0.5, y + 0.5, r, r))
-
-
-def _pip_arm(f: Frame, shoulder: Px, hand: Px) -> None:
- """A chubby sleeve from ``shoulder`` to a round hand at ``hand``."""
- _pip_suit(f, thick(line(*shoulder, *hand)), 1)
- _pip_hand(f, *hand)
-
-
-def _pip_curl(f: Frame, bob: int = 0) -> None:
- """The single curl of hair on top; ``bob`` flips its tip up or down."""
- tip = {0: [(28, 7), (26, 7)], 1: [(29, 7)], -1: [(29, 8)]}[bob]
- f.part(polyline([(23, 9), (23, 7), (24, 5), (26, 4), (28, 5), *tip]), PIP_HAIR)
+#: Polishing the shell: the right stalk leans back to follow the rag, then a
+#: gleam sweeps across and Shelly is very proud of it.
+_SHELLY_POLISH: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((8, 14), (19, 12), "look_right", "look_right", "closed"),
+ ((9, 14), (20, 11), "look_right", "up_right", "closed"),
+ ((8, 14), (19, 12), "look_right", "look_right", "closed"),
+ ((9, 14), (20, 11), "look_right", "up_right", "closed"),
+ ((8, 14), (19, 12), "look_right", "look_right", "rest"),
+ ((8, 14), (17, 13), "happy", "happy", "smile"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
+)
+#: A raindrop: both eyes watch it fall, the left stalk catches it, dips under
+#: the weight, then stretches up delighted.
+_SHELLY_RAIN: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((8, 15), (17, 14), "up", "up_left", "rest"),
+ ((8, 14), (17, 14), "up", "up_left", "half"),
+ ((8, 14), (17, 14), "up", "up_left", "half"),
+ ((8, 17), (17, 14), "closed", "wide", "open"),
+ ((8, 12), (17, 12), "happy", "happy", "smile"),
+ ((8, 13), (17, 13), "happy", "happy", "smile"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
+)
+#: Turbo: crouch, ZOOM a few pixels forward with the stalks blown back, a
+#: whiplash stop, and a sheepish slow crawl back.
+_SHELLY_TURBO: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((10, 17), (19, 16), "look_left", "look_left", "closed"),
+ ((12, 18), (21, 17), "look_left", "look_left", "wide"),
+ ((14, 19), (22, 18), "look_left", "look_left", "wide"),
+ ((7, 14), (16, 13), "wide", "wide", "half"),
+ ((8, 15), (17, 14), "look_right", "look_right", "closed"),
+ ((8, 15), (17, 14), "look_right", "open", "rest"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
+)
+#: (dx, stretch) per turbo frame.
+_SHELLY_TURBO_MOVE = ((0, 0), (0, -1), (-2, 0), (-4, 0), (-4, -1), (-3, 0), (-1, 0), (0, 0))
+#: Stalk knot: the stalks cross, tie into a knot, Shelly sees stars, shakes
+#: them loose and the stalks spring back.
+_SHELLY_KNOT: tuple[_ShellyActFrame, ...] = (
+ (_REST_L, _REST_R, "open", "open", "rest"),
+ ((13, 14), (12, 15), "look_right", "look_left", "closed"),
+ ((17, 14), (8, 15), "wide", "wide", "half"),
+ ((16, 13), (9, 14), "x", "x", "frown"),
+ ((16, 13), (9, 14), "x", "x", "frown"),
+ ((13, 14), (12, 15), "closed", "closed", "closed"),
+ ((7, 15), (18, 14), "open", "open", "half"),
+ (_REST_L, _REST_R, "open", "open", "rest"),
+)
+#: Where the knot's loop sits on the crossed stalks, per frame.
+_SHELLY_KNOTS: dict[int, Px] = {2: (12, 21), 3: (12, 20), 4: (12, 20)}
+#: (dx) per knot frame: a dizzy shake to loosen the knot.
+_SHELLY_KNOT_SHAKE = (0, 0, 0, 0, -1, 1, 0, 0)
+
+_SHELLY_ACT_FRAMES: dict[str, tuple[_ShellyActFrame, ...]] = {
+ "peek_hide": _SHELLY_PEEK_HIDE,
+ "leaf_munch": _SHELLY_LEAF_MUNCH,
+ "shell_polish": _SHELLY_POLISH,
+ "rain_drop": _SHELLY_RAIN,
+ "turbo": _SHELLY_TURBO,
+ "stalk_knot": _SHELLY_KNOT,
+}
-def _pip_eyes(f: Frame, style: str) -> None:
- for x, y in _PIP_EYE_AT:
- if style in _PIP_LIDS:
- f.paint(from_rows(x, y, _PIP_LIDS[style]), OUTLINE)
- continue
- lx, ly = _PIP_LOOK[style]
- x, y = x + lx, y + ly
- top, h = (y - 1, 6) if style == "wide" else (y, 5)
- f.paint(_oval(x, top, 4, h), PIP_EYE)
- f.paint({(x + 2, top + 1), (x + 2, top + 2), (x + 1, top + 1)}, FX_WHITE)
- f.paint({(x + 1, top + h - 2)}, FX_DIM)
+def _shelly_figure(
+ f: Frame, tips: tuple[Px, Px], looks: tuple[str, str], mouth: str, knot: Px | None = None
+) -> None:
+ """The idle snail with chosen stalk tips, looks and mouth (no desk, no spin)."""
+ for base, tip in zip(_SHELLY_STALK_BASES, tips, strict=True):
+ _shelly_stalk(f, base, tip)
+ if knot is not None:
+ loop = ellipse(knot[0] + 0.5, knot[1] + 0.5, 2.2, 2.2) - {knot}
+ f.part(loop, SHELLY_BODY)
+ f.paint({knot}, OUTLINE)
+ foot = ellipse(26, 41, 17, 3.2)
+ body = foot | ellipse(13, 33, 6, 8)
+ f.part(body, _shade(body, SHELLY_BODY, SHELLY_BODY_LIGHT, SHELLY_BODY_DARK, 1))
+ shell = ellipse(28, 28, 11, 11)
+ f.part(shell, _shade(shell, SHELLY_SHELL, SHELLY_SHELL_LIGHT, SHELLY_SHELL_DARK))
+ f.paint(_spiral(28.0, 28.0, 0.0) & eroded(shell, 1), SHELLY_SPIRAL)
+ f.paint(rect(12, 37, 13, 37), SHELLY_BLUSH)
+ draw_mouth(f, mouth, 8, 34, 3)
+ _shelly_eye(f, looks[0], tips[0], right=False)
+ _shelly_eye(f, looks[1], tips[1], right=True)
+
+
+def _shelly_tucked(f: Frame, i: int) -> None:
+ """Tucked into the shell (no night flag, no glow); a stalk may peek out."""
+ foot = ellipse(26, 43, 13, 1.6)
+ f.part(foot, SHELLY_BODY_DARK)
+ shell = ellipse(27, 31, 11, 10.5)
+ f.part(shell, _shade(shell, SHELLY_SHELL, SHELLY_SHELL_LIGHT, SHELLY_SHELL_DARK))
+ f.paint(_spiral(27.0, 31.0, 0.0, r_max=8.0) & eroded(shell, 1), SHELLY_SPIRAL)
+ f.paint(ellipse(18.5, 37.5, 2, 2) & shell, SHELLY_SPIRAL)
+ peek = _SHELLY_PEEK_STALK.get(i)
+ if peek is not None:
+ tip, look = peek
+ f.part(line(18, 37, *tip), SHELLY_BODY)
+ _shelly_eye(f, look, tip, right=False)
+
+
+def _draw_shelly_act(f: Frame, pose: Pose) -> None:
+ """One idle-act frame from the act's table."""
+ entry = _SHELLY_ACT_FRAMES[pose.act][pose.i]
+ with f.offset(pose.dx, pose.dy):
+ if entry is None:
+ _shelly_tucked(f, pose.i)
+ return
+ left, right, left_look, right_look, mouth = entry
+ knot = _SHELLY_KNOTS.get(pose.i) if pose.act == "stalk_knot" else None
+ _shelly_figure(f, (left, right), (left_look, right_look), mouth, knot)
-def _pip_paci(f: Frame, x: float, y: float, suck: int = 0) -> None:
- """The pacifier with its centre at ``(x, y)``: a pink shield, a knob and a
- blue ring below; sucking draws it in, so it narrows and the ring lifts."""
- ring = ellipse(x, y + 3.5 - suck, 2.5, 2.5)
- f.part(ring - ellipse(x, y + 3.5 - suck, 1.2, 1.2), PIP_PACI_RING)
- shield = ellipse(x, y, 4.0 - 0.7 * suck, 2.0)
- f.part(shield, {p: PIP_PACI_LIGHT if p[1] < y - 1 else PIP_PACI for p in shield})
- knob = math.floor(x)
- f.paint(rect(knob - 1, math.floor(y), knob, math.floor(y)), PIP_PACI_LIGHT)
+def _shelly_act_pose(name: str) -> Callable[[int], Pose]:
+ """The act's frame pose; only turbo and the knot's shake move the body."""
+ def pose(i: int) -> Pose:
+ if name == "turbo":
+ dx, stretch = _SHELLY_TURBO_MOVE[i]
+ return Pose("idle", i, dx=dx, stretch=stretch, act=name)
+ if name == "stalk_knot":
+ return Pose("idle", i, dx=_SHELLY_KNOT_SHAKE[i], act=name)
+ return Pose("idle", i, act=name)
-def _pip_mouth(f: Frame, pose: Pose) -> None:
- mouth = pose.mouth
- if mouth == "paci":
- suck = 0
- if pose.state == "idle" and pose.i < len(_PIP_SUCK):
- suck = _PIP_SUCK[pose.i]
- elif pose.state == "working":
- suck = 1 if any(k is not None for k in _PIP_BANG[pose.i % 8]) else 0
- _pip_paci(f, CX, 26, suck)
- elif mouth == "o":
- f.paint(rect(23, 25, 24, 26), MOUTH_DARK)
- f.paint({(23, 25), (24, 25)}, OUTLINE)
- elif mouth == "chew":
- f.paint(rect(22, 26, 25, 26) if pose.i % 2 else rect(23, 26, 24, 26), OUTLINE)
- elif mouth == "grin":
- draw_mouth(f, "open", 21, 25, 6)
- elif mouth == "wail":
- draw_mouth(f, "wide", 21, 25, 6)
- f.paint({(20, 26), (27, 26)}, OUTLINE) # the corners pulled down
- else:
- draw_mouth(f, mouth, 22, 25, 4)
-
-
-def _pip_head(f: Frame, pose: Pose, *, bob: int = 0) -> None:
- """Ears, curl, the round head and the face (head centred on (CX, 19))."""
- for ear in (ellipse(11.5, 20.5, 2.2, 2.6), mirrored(ellipse(11.5, 20.5, 2.2, 2.6))):
- _pip_skin(f, ear)
- _pip_curl(f, bob)
- head = ellipse(CX, 19, 12, 11)
- f.part(head, _shade(head, PIP_SKIN, PIP_SKIN_LIGHT, PIP_SKIN_DARK))
- f.paint({(11, 20), (36, 20)}, PIP_SKIN_DARK)
- cheek = rect(14, 23, 16, 24)
- flush = pose.state == "error"
- f.paint(cheek | mirrored(cheek), PIP_FLUSH if flush else BLUSH)
- if flush:
- f.paint(rect(13, 22, 17, 22) | rect(30, 22, 34, 22), BLUSH)
- _pip_eyes(f, pose.eyes)
- _pip_mouth(f, pose)
-
-
-def _pip_arms(pose: Pose) -> tuple[tuple[Px, Px, bool], ...]:
- """(shoulder, hand, in front of the head) for each arm of the sitting baby."""
- state, i = pose.state, pose.i
- rest_l, rest_r = ((16, 33), (14, 39), False), ((31, 33), (33, 39), False)
- if state == "listening":
- return rest_l, ((32, 33), (37, 21), True)
- if state == "thinking":
- hand = (29, 30) if i < 4 else ((35, 27) if i % 2 else (34, 28))
- return rest_l, ((31, 33), hand, True)
- if state == "talking":
- lift = (0, 0, 3, 5)[i % 4]
- return ((16, 33), (13, 38 - lift), False), ((31, 33), (34, 38 - lift), False)
- if state == "success":
- if _PIP_CLAP[i % 8]:
- return ((17, 33), (21, 33), True), ((30, 33), (26, 33), True)
- return ((16, 33), (10, 29), False), ((31, 33), (37, 29), False)
- if state == "error":
- up = i % 2
- return ((16, 33), (10, 30 - 2 * up), False), ((31, 33), (37, 28 + 2 * up), False)
- if state == "working":
- return () # the hands are on the keyboard, drawn with it
- if state == "searching":
- return rest_l, ((31, 33), (35, 30), True)
- return rest_l, rest_r
+ return pose
-def draw_pip(f: Frame, pose: Pose) -> None:
- if pose.state == "sleeping":
- _draw_pip_asleep(f, pose)
- elif pose.state == "held":
- _draw_pip_lifted(f, pose)
- else:
- _draw_pip_sitting(f, pose)
+def _shelly_trail(f: Frame, start: int = 30) -> None:
+ """The idle slime trail, so an act blends in with the breathing row."""
+ f.paint({(x, 45) for x in range(start, 47) if x % 4 != 1}, SHELLY_SLIME)
-def _pip_feet(f: Frame, kick: tuple[int, int]) -> None:
- for side, lift in enumerate(kick):
- foot = ellipse(17.5, 44.5 - lift, 3.4, 2.2)
- toes = {(15, 43 - lift), (17, 43 - lift)}
- if side:
- foot, toes = mirrored(foot), mirrored(toes)
- _pip_skin(f, foot)
- f.paint(toes, PIP_SKIN_LIGHT)
+def _shelly_peek_fx(f: Frame, pose: Pose) -> None:
+ """Puffs of dust as Shelly pops into the shell, a "?" while peeking."""
+ _shelly_trail(f)
+ if pose.i == 2:
+ f.paint({(12, 41), (11, 39), (13, 38), (40, 41), (41, 39), (39, 38)}, FX_DIM)
+ if pose.i in (4, 5):
+ q = ("###", "..#", ".#.", "...", ".#.")
+ f.glyph(7 if pose.i == 4 else 20, 19 if pose.i == 4 else 18, q, {"#": FX_WHITE})
-def _draw_pip_sitting(f: Frame, pose: Pose) -> None:
- state, i = pose.state, pose.i
- kick = (0, 0)
- if state == "idle" and i < len(_PIP_IDLE_KICK):
- kick = _PIP_IDLE_KICK[i]
- elif state == "success":
- kick = (1, 1) if pose.dy <= -2 else (0, 0)
- elif state == "error":
- kick = (i % 2, 1 - i % 2) # a tantrum: the feet drum
- elif state == "talking":
- kick = (0, 0, 1, 1)[i % 4], (0, 0, 0, 1)[i % 4]
- bob = 1 if state == "success" and pose.dy <= -2 else -1 if state == "error" else 0
- tilt = _PIP_TILT[i % len(_PIP_TILT)] if state == "listening" else 0
- arms = _pip_arms(pose)
- with f.offset(pose.dx, min(pose.dy, 0)):
- _pip_feet(f, kick) # planted: a nod never pushes them down
- with f.offset(pose.dx, pose.dy):
- # A raised arm's sleeve goes behind the body; only its hand comes forward.
- for shoulder, hand, front in arms:
- if front:
- _pip_arm(f, shoulder, hand)
- torso = ellipse(CX, 37, 10, 7.5)
- _pip_suit(f, torso)
- f.paint(from_rows(25, 36, _PIP_STAR), PIP_MINT)
- for shoulder, hand, front in arms:
- if not front:
- _pip_arm(f, shoulder, hand)
- with f.offset(tilt, 0):
- _pip_head(f, pose, bob=bob)
- if state == "listening" and i == 0:
- _pip_paci(f, CX, 31) # popping out of the open mouth
- elif state == "listening":
- _pip_paci(f, 22, 40) # landed in the lap
- if state == "thinking":
- _pip_rattle(f, pose)
- if state == "searching":
- _pip_magnifier(f, pose)
- for _shoulder, hand, front in arms:
- if front:
- # The sleeve stays behind; clapping hands are a size bigger.
- _pip_hand(f, *hand, 2.7 if state == "success" else 2.2)
-
-
-def _pip_rattle(f: Frame, pose: Pose) -> None:
- """A rattle in the right hand: chewed at the mouth, then shaken by the cheek."""
- if pose.i < 4:
- ball, end = (25.5, 27.0), (30, 31)
- else:
- ball, end = ((38.5, 21.0), (36, 27)) if pose.i % 2 else ((37.5, 22.0), (35, 28))
- f.part(thick(line(math.floor(ball[0]), math.floor(ball[1]), *end)), PIP_TOYS[1])
- head = ellipse(*ball, 2.8, 2.8)
- f.part(head, {p: PIP_MINT_LIGHT if p in eroded(head) else PIP_MINT for p in head})
- f.paint({(math.floor(ball[0]) - 1, math.floor(ball[1]) - 1)}, FX_WHITE)
-
-
-def _pip_magnifier(f: Frame, pose: Pose) -> None:
- """A toy magnifier over the right eye: inside the lens the eye is huge and
- follows the search."""
- lx, _ly = _PIP_LOOK.get(pose.eyes, (0, 0))
- cx, cy = 29.5, 18.5
- f.part(thick(line(33, 23, 35, 29)), PIP_TOYS[0])
- lens = ellipse(cx, cy, 6, 6)
- rim = lens - ellipse(cx, cy, 4.6, 4.6)
- f.paint(lens, PIP_SKIN_LIGHT)
- eye = _oval(27 + lx, 15, 6, 7)
- f.paint(eye, PIP_EYE)
- f.paint(rect(30 + lx, 16, 31 + lx, 17) | {(29 + lx, 16)}, FX_WHITE)
- f.paint({(28 + lx, 20)}, FX_DIM)
- f.part(rim, shade(rim, PIP_TOYS[0], light=hexc("#ff9e9e"), dark=hexc("#c94a4a"), dark_depth=1))
- f.paint({(25, 16), (26, 15)}, FX_WHITE)
-
-
-def _draw_pip_lifted(f: Frame, pose: Pose) -> None:
- """Held: lifted under the arms, the arms up, the legs dangling and kicking."""
- lag = -pose.dx
- left, right = _PIP_HELD_KICK[pose.i % len(_PIP_HELD_KICK)]
- with f.offset(pose.dx, 0):
- for hip, lift, out in (((20, 38), left, -1), ((27, 38), right, 1)):
- foot = (hip[0] + out * (1 + lift) + lag, 44 - lift)
- _pip_suit(f, thick(line(*hip, *foot)), 1)
- _pip_skin(f, ellipse(foot[0] + 0.5 + out, foot[1] + 1.0, 2.6, 1.8))
- torso = ellipse(CX, 33, 8.5, 7)
- _pip_suit(f, torso)
- f.paint(from_rows(24, 32, _PIP_STAR), PIP_MINT)
- _pip_arm(f, (17, 29), (9, 13))
- _pip_arm(f, (30, 29), (38, 13))
- with f.offset(0, -3):
- _pip_head(f, pose, bob=1 if pose.i % 2 else 0)
+#: The leaf held up to the mouth, and the bites taken out of it so far.
+_SHELLY_BITES: tuple[tuple[float, float, float], ...] = ((6.5, 33.5, 1.8), (6.0, 36.5, 2.2))
-def _draw_pip_asleep(f: Frame, pose: Pose) -> None:
- """Asleep on a pillow under a mint blanket that rises and falls with each
- breath; the pacifier keeps a slow suck going."""
+def _shelly_leaf_fx(f: Frame, pose: Pose) -> None:
+ """A leaf pops up in front of the mouth; two chomps take bites out of it,
+ crumbs fall, and the last nibble vanishes with a happy smile."""
+ _shelly_trail(f)
i = pose.i
- rise = SLEEP_BREATH[i % len(SLEEP_BREATH)]
- pillow = ellipse(12, 41, 11, 4)
- f.part(pillow, _shade(pillow, PIP_PILLOW, FX_WHITE, PIP_PILLOW_DARK, 1))
- with f.offset(-10, 15):
- _pip_curl(f)
- head = ellipse(14, 34, 9, 8.5)
- _pip_skin(f, head, 2)
- f.paint(rect(6, 37, 7, 38) | rect(19, 37, 20, 38), BLUSH)
- for x in (8, 16):
- f.paint(from_rows(x, 32, _PIP_LIDS["sleep"][1:]), OUTLINE)
- _pip_paci(f, 14, 39, rise)
- blanket = ellipse(32, 46, 14.5, 13 + rise) & rect(0, 0, CELL - 1, 45)
- f.part(blanket, _shade(blanket, PIP_MINT, PIP_MINT_LIGHT, PIP_MINT_DARK, 1))
- f.paint({p for p in blanket if (p[0] + 2 * p[1]) % 7 == 0 and p in eroded(blanket)}, FX_WHITE)
- _pip_hand(f, 23, 34 - rise) # a fist holding the blanket's edge
-
-
-# -- Pip's effects ------------------------------------------------------------
-
-
-#: Listening: sound arcs rolling in towards the cupped hand, (x, fading).
-_PIP_INCOMING: tuple[tuple[tuple[int, bool], ...], ...] = (
- ((44, False),),
- ((42, False),),
- ((40, False), (44, False)),
- ((40, True), (42, False)),
- ((40, False),),
- ((41, True),),
-)
+ if 1 <= i <= 6:
+ leaf = ellipse(3.5, 34, 2.5, 5.5)
+ bites = 0 if i < 3 else 1 if i < 5 else 2
+ for cx, cy, r in _SHELLY_BITES[:bites]:
+ leaf -= ellipse(cx, cy, r, r)
+ if i == 6:
+ leaf = rect(3, 37, 4, 39)
+ f.part(leaf, {p: SHELLY_LEAF_DARK if p[0] == 3 else SHELLY_LEAF for p in leaf})
+ stem = line(3, 40, 2, 42)
+ f.part(stem, SHELLY_LEAF_DARK)
+ if i == 1:
+ f.paint({(1, 27), (6, 27), (0, 30)}, SPARK)
+ # Crumbs fall after each chomp.
+ crumbs = {3: ((7, 40),), 4: ((8, 42), (6, 41)), 5: ((7, 40), (5, 43)), 6: ((7, 42), (5, 44))}
+ f.paint(set(crumbs.get(i, ())), SHELLY_LEAF_DARK)
-def _pip_listening_fx(f: Frame, pose: Pose) -> None:
- """Sound arcs roll in from the right to the hand cupped at the ear."""
- with f.offset(pose.dx, pose.dy):
- for x, fading in _PIP_INCOMING[pose.i % len(_PIP_INCOMING)]:
- arc = {(x + ax, 21 + ay) for ax, ay in _ARC_L}
- f.paint({p for p in arc if p[0] < CELL}, ARC_FADE if fading else ARC)
+#: Rag positions (top-left) while wiping, back and forth over the shell top.
+_SHELLY_RAG_AT: dict[int, Px] = {1: (22, 14), 2: (29, 13), 3: (23, 14), 4: (30, 13)}
-def _pip_thinking_fx(f: Frame, pose: Pose) -> None:
- """A thought cloud with a toy star that twinkles; bubbles rise into it."""
+def _shelly_polish_fx(f: Frame, pose: Pose) -> None:
+ """A little blue rag wipes the shell, a gleam sweeps across it and a
+ sparkle pings off the top."""
+ _shelly_trail(f)
i = pose.i
- with f.offset(pose.dx, pose.dy + 1):
- rise = i % 4
- f.part(rect(11 - rise // 2, 9 - rise // 2, 12 - rise // 2, 10 - rise // 2), PIP_PILLOW)
- cloud = ellipse(6, 5, 4, 3.5) | ellipse(11, 3.5, 4.5, 3.5) | ellipse(15, 5.5, 3, 3)
- cloud |= rect(4, 6, 16, 7)
- f.part(cloud, {p: PIP_PILLOW_DARK if p[1] >= 7 else PIP_PILLOW for p in cloud})
- star = ("..#..", ".###.", "#####", ".#.#.") if i % 4 < 2 else (".#.", "###", ".#.")
- x = 8 if len(star) == 4 else 9
- f.paint(from_rows(x, 2 if len(star) == 4 else 3, star), PIP_TOYS[1])
- if i % 4 >= 2:
- f.paint({(10, 4)}, SPARK_CORE)
- if pose.i >= 4:
- # Shaking the rattle: little rattle ticks round its head.
- k = pose.i % 2
- f.paint({(42 + k, 17), (43 + k, 16), (43, 24 + k), (44, 25 + k)}, ARC)
-
-
-_PIP_NOTE = (".##", ".#.", ".#.", "##.")
-
-
-def _pip_talking_fx(f: Frame, pose: Pose) -> None:
- """Babble notes pop out beside the face, more of them the louder."""
- with f.offset(pose.dx, pose.dy):
- if pose.i >= 1:
- f.paint({(38, 25), (39, 24)}, ARC)
- if pose.i >= 2:
- f.glyph(40, 17, _PIP_NOTE, {"#": PIP_TOYS[4]})
- if pose.i >= 3:
- f.glyph(5, 14, _PIP_NOTE, {"#": PIP_TOYS[2]})
- f.paint({(9, 25), (8, 24)}, ARC)
-
-
-_PIP_HEART_S = ("#.#", "###", ".#.")
-_PIP_HEART_L = ("##.##", "#o###", "#####", ".###.", "..#..")
-#: Confetti flakes (x, y, colour index, first frame) that tumble down.
-_PIP_CONFETTI = (
- (6, 2, 0, 0),
- (40, 1, 2, 1),
- (14, 1, 3, 2),
- (34, 3, 4, 2),
- (3, 12, 1, 3),
- (44, 10, 0, 4),
-)
-
-
-def _pip_success_fx(f: Frame, pose: Pose) -> None:
- """Clap sparks between the hands, confetti tumbling down and a heart."""
+ rag = _SHELLY_RAG_AT.get(i)
+ if rag is not None:
+ x, y = rag
+ f.glyph(x, y, ("####", "#oo#", "####"), {"#": SHELLY_RAG, "o": SHELLY_RAG_LIGHT})
+ side = -1 if i % 2 == 0 else 1 # the wipe's motion lines trail behind it
+ mx = x - 2 if side > 0 else x + 5
+ f.paint({(mx, y), (mx, y + 2)}, FX_DIM)
+ if i in (5, 6):
+ inner = ellipse(28, 28, 9.5, 9.5)
+ x0 = 20 if i == 5 else 28
+ stroke = {(x0 + t, 34 - t) for t in range(-6, 7)}
+ gleam = stroke | shifted(stroke, 1, 0)
+ f.paint(gleam & inner, FX_WHITE)
+ fx_sparkles(f, i, ((37, 16, 5), (41, 31, 6)))
+
+
+def _shelly_rain_fx(f: Frame, pose: Pose) -> None:
+ """A raindrop falls onto the left stalk, splashes, and a heart pops up."""
+ _shelly_trail(f)
i = pose.i
- for x, y, color, start in _PIP_CONFETTI:
- age = i - start
- if not 0 <= age <= 4:
- continue
- fy = y + 3 * age
- flake = rect(x, fy, x + 1, fy) if (age + color) % 2 else rect(x, fy, x, fy + 1)
- f.part(flake, PIP_TOYS[color])
- if _PIP_CLAP[i % 8]:
- # Clap! A spark pops on either side of the hands.
- y = 32 + pose.dy
- f.glyph(15, y, _SPARK_S, _SPARK_PALETTE)
- f.glyph(30, y, _SPARK_S, _SPARK_PALETTE)
- age = i - 2
- if 0 <= age <= 4:
- rows = _PIP_HEART_L if age in (1, 2, 3) else _PIP_HEART_S
- f.glyph(40, 18 - age, rows, {"#": PIP_HEART, "o": PIP_HEART_SHINE})
-
-
-#: Error: tear drops arcing out of each eye, (dx, dy) from the eye per frame.
-_PIP_TEARS: tuple[tuple[Px, ...], ...] = (
- ((-2, 1),),
- ((-3, 0), (-5, 2)),
- ((-4, -1), (-7, 1), (-8, 5)),
- ((-6, 0), (-9, 3), (-3, 0)),
- ((-8, 2), (-5, -1), (-10, 6)),
- ((-7, 1), (-3, 0)),
-)
-_PIP_DROP = (".#.", "###", "#o#", ".#.")
-
-
-def _pip_error_fx(f: Frame, pose: Pose) -> None:
- """Tears spurt sideways out of both scrunched eyes and stream down the
- cheeks; the pacifier tumbles away."""
- with f.offset(pose.dx, pose.dy):
- streams = rect(15, 21, 15, 24) | rect(32, 21, 32, 24)
- f.paint(streams, SWEAT)
- for dx, dy in _PIP_TEARS[pose.i % len(_PIP_TEARS)]:
- f.glyph(13 + dx, 18 + dy, _PIP_DROP, {"#": SWEAT, "o": SWEAT_SHINE})
- f.glyph(32 - dx, 18 + dy, _PIP_DROP, {"#": SWEAT, "o": SWEAT_SHINE})
- fall = min(pose.i, 3)
- _pip_paci(f, 35 + 2 * fall, 31 + 3 * fall, 0)
-
-
-def _pip_sleeping_fx(f: Frame, pose: Pose) -> None:
- """The z marks drift up off the blanket."""
- fx_zzz(f, pose.i, 26, 22)
-
-
-def _pip_working_fx(f: Frame, pose: Pose) -> None:
- """A toy keyboard with five big coloured keys: Pip bangs them with both
- hands, a struck key flashes and a note in its colour flies off the side."""
+ palette = {"#": SWEAT, "o": SWEAT_SHINE}
+ fall = {1: 1, 2: 4, 3: 7}
+ if i in fall:
+ f.glyph(7, fall[i], _DROP, palette)
+ if i == 4:
+ f.glyph(7, 10, (".#.", "#o#"), palette) # sitting on top of the eye
+ f.paint({(4, 13), (3, 12), (12, 13), (13, 12)}, SWEAT)
+ if i in (5, 6):
+ heart = ("##.##", "#####", ".###.", "..#..")
+ f.glyph(11, 5 - (i - 5) * 2, heart, {"#": SHELLY_BLUSH})
+ if i == 5:
+ f.paint({(3, 9), (14, 8), (5, 6)}, SWEAT)
+
+
+def _shelly_turbo_fx(f: Frame, pose: Pose) -> None:
+ """Speed lines stream off the back of the shell during the dash and dust
+ kicks up where Shelly brakes."""
+ _shelly_trail(f, 30 + min(pose.dx, 0))
+ i, dx = pose.i, pose.dx
+ if i in (2, 3):
+ length = 4 if i == 2 else 7
+ for y, extra in ((21, 0), (27, 2), (33, 0)):
+ x0 = 41 + dx
+ f.paint({(x, y) for x in range(x0, min(x0 + length + extra, CELL))}, FX_DIM)
+ if i == 3:
+ f.paint({(44, 40), (46, 38), (45, 42)}, FX_DIM)
+ if i == 4:
+ f.paint({(3, 43), (1, 41), (2, 39), (0, 43)}, FX_DIM) # the brake's dust
+ if i == 5:
+ f.glyph(21 + dx, 17, _DROP, {"#": SWEAT, "o": SWEAT_SHINE}) # a sheepish bead
+
+
+def _shelly_knot_fx(f: Frame, pose: Pose) -> None:
+ """Dizzy stars circle the knotted stalks until a shake shakes them off."""
+ _shelly_trail(f)
i = pose.i
- case = rounded_rect(8, 36, 39, 45, 2)
- f.part(case, shade(case, PIP_TOY[0], light=PIP_TOY[1], dark=PIP_TOY[2], dark_depth=1))
- f.paint({(22, 43), (24, 43), (26, 43)}, PIP_TOY[2]) # the speaker
- struck = {k for k in _PIP_BANG[i % len(_PIP_BANG)] if k is not None}
- for k, color in enumerate(PIP_TOYS):
- x = 11 + 5 * k
- if k in struck:
- f.part(rect(x, 39, x + 3, 40), color)
- f.paint(rect(x, 39, x + 3, 39), FX_WHITE)
- else:
- f.part(rect(x, 38, x + 3, 40), color)
- left, right = _PIP_BANG[i % len(_PIP_BANG)]
- for key, shoulder, rest in ((left, (16, 33), 13), (right, (31, 33), 34)):
- hand = (12 + 5 * key, 37) if key is not None else (rest, 31)
- _pip_arm(f, shoulder, hand)
- # Notes from earlier strikes fly out, left keys to the left, right to the right.
- for age in (1, 2):
- for key in _PIP_BANG[(i - age) % len(_PIP_BANG)]:
- if key is None:
- continue
- x = 4 - age if key < 2 else 41 + age
- f.glyph(x, 31 - 4 * age, _PIP_NOTE, {"#": PIP_TOYS[key]})
+ if 3 <= i <= 5:
+ with f.offset(pose.dx, 0):
+ for k in range(2 if i == 5 else 3):
+ angle = 2.0 * math.pi * (i / 4.0 + k / 3.0)
+ x = math.floor(12.5 + round(math.cos(angle) * 8.0, 6))
+ y = math.floor(7.5 + round(math.sin(angle) * 2.0, 6))
+ f.glyph(x - 1, y - 1, _SPARK_S, _SPARK_PALETTE)
-def _pip_searching_fx(f: Frame, pose: Pose) -> None:
- """Dotted glances out of the lens, and a sparkle when something turns up."""
- sweep = SEARCH_SWEEP[pose.i % len(SEARCH_SWEEP)]
- with f.offset(pose.dx, pose.dy):
- if sweep < -2:
- f.paint({(9, 18), (6, 18), (3, 18)}, ARC_FADE)
- elif sweep > 2:
- f.paint({(38, 14), (41, 13), (44, 12)}, ARC_FADE)
- fx_sparkles(f, pose.i, ((42, 6, 3),))
+SHELLY_ACTS: tuple[IdleAct, ...] = (
+ IdleAct("turbo", 8, 10, _shelly_act_pose("turbo"), _shelly_turbo_fx),
+ IdleAct("peek_hide", 8, 7, _shelly_act_pose("peek_hide"), _shelly_peek_fx),
+ IdleAct("leaf_munch", 8, 8, _shelly_act_pose("leaf_munch"), _shelly_leaf_fx),
+ IdleAct("shell_polish", 8, 8, _shelly_act_pose("shell_polish"), _shelly_polish_fx),
+ IdleAct("rain_drop", 8, 8, _shelly_act_pose("rain_drop"), _shelly_rain_fx),
+ IdleAct("stalk_knot", 8, 8, _shelly_act_pose("stalk_knot"), _shelly_knot_fx),
+)
-def _pip_held_fx(f: Frame, pose: Pose) -> None:
- """Wheee: swing streaks behind the dangling legs and little hearts."""
- sway = pose.dx
- with f.offset(sway, 0):
- if sway < 0:
- f.paint(line(36, 36, 36, 42) | line(38, 38, 38, 41), ARC_FADE)
- elif sway > 0:
- f.paint(line(11, 36, 11, 42) | line(9, 38, 9, 41), ARC_FADE)
- k = pose.i % 3
- f.glyph(41, 26 - 2 * k, _PIP_HEART_S, {"#": PIP_HEART})
- if pose.i % 2:
- f.glyph(3, 23, _PIP_HEART_S, {"#": PIP_HEART})
-
-
-PIP = PetDesign(
- id="pip",
- name="Pip",
- description="A chubby baby with a pacifier who babbles when you talk and naps under a blanket.",
- draw=draw_pip,
- pose=pip_pose,
- waist=40,
+SHELLY = PetDesign(
+ id="shelly",
+ name="Shelly",
+ description="A patient snail whose shell spins while it thinks and who hides inside to sleep.",
+ draw=draw_shelly,
+ pose=shelly_pose,
+ waist=38,
anchors=Anchors(
- arcs_left=(8, 20),
- arcs_right=(39, 20),
- dots=(19, 3),
- zzz=(26, 22),
- bang=(42, 3),
- sparkles=((6, 12, 1), (41, 9, 2), (5, 32, 3), (42, 30, 3)),
+ arcs_left=(8, 6),
+ arcs_right=(21, 7),
+ dots=(27, 8),
+ zzz=(35, 15),
+ bang=(40, 4),
+ sweat=(17, 24),
+ sparkles=((3, 26, 1), (41, 10, 2), (3, 40, 3), (44, 28, 3)),
),
fx={
- "listening": _pip_listening_fx,
- "thinking": _pip_thinking_fx,
- "talking": _pip_talking_fx,
- "success": _pip_success_fx,
- "error": _pip_error_fx,
- "sleeping": _pip_sleeping_fx,
- "working": _pip_working_fx,
- "searching": _pip_searching_fx,
- "held": _pip_held_fx,
+ "idle": _shelly_idle_fx,
+ "listening": _shelly_listening_fx,
+ "thinking": _shelly_thinking_fx,
+ "talking": _shelly_talking_fx,
+ "success": _shelly_success_fx,
+ "working": _shelly_laptop_fx,
+ "searching": _shelly_searching_fx,
+ "held": _shelly_held_fx,
},
+ acts=SHELLY_ACTS,
)
+
# -- Ember: the baby dragon ---------------------------------------------------------
#
# A fresh hatchling: a chubby red dragon with a big round head, huge shiny
@@ -4260,6 +5787,8 @@ _EMBER_LIDS: dict[str, tuple[str, ...]] = {
#: Scrunched shut after a sooty cough: > <.
"squint": (".....", "##...", "..##.", "....#", "..##.", "##..."),
"x": (".....", "#...#", ".#.#.", "..#..", ".#.#.", "#...#"),
+ #: Dizzy after chasing its tail: a spiral in each eye.
+ "dizzy": (".###.", "#...#", "#.#.#", "#.##.", "#....", ".####"),
}
#: Ear-fin tips (left fin; the right one is mirrored) per mood.
_EMBER_FIN_TIPS: dict[str, tuple[float, float]] = {
@@ -4516,7 +6045,9 @@ def _ember_head(
def draw_ember(f: Frame, pose: Pose) -> None:
- if pose.state == "sleeping":
+ if pose.act:
+ _draw_ember_act(f, pose)
+ elif pose.state == "sleeping":
_draw_ember_curled(f, pose)
elif pose.state == "held":
_draw_ember_dangling(f, pose)
@@ -4995,6 +6526,536 @@ def _ember_held_fx(f: Frame, pose: Pose) -> None:
_ember_puff(f, 39 + sway, 19, 1.9, EMBER_SMOKE_LIGHT)
+# -- Ember's idle acts --------------------------------------------------------
+
+
+@dataclass(frozen=True)
+class _EmberCell:
+ """One frame of an idle act: the pose plus the parts only Ember moves."""
+
+ dx: int = 0
+ dy: int = 0
+ eyes: str = "open"
+ mouth: str = "rest"
+ stretch: int = 0
+ wings: tuple[str, str] = ("rest", "rest")
+ #: The tail's (sway, lift, side); side -1 swings it round to the left hip.
+ tail: tuple[int, int, int] = (0, 0, 1)
+ fins: tuple[str, str] = ("rest", "rest")
+ #: (shoulder, claw) per arm; ``None`` keeps both claws on the belly.
+ arms: tuple[tuple[Px, Px], ...] | None = None
+ #: Claws drawn in front of the head (holding the eggshell hood).
+ hands: tuple[Px, ...] = ()
+ cap: int | None = 0
+ #: The eggshell pulled down over the eyes, its jagged rim on this row
+ #: (0 = the cap sits on top as usual).
+ hood: int = 0
+ #: The coal in the belly, 0 (out) .. 3 (white-hot).
+ glow: int = 0
+ soot: bool = False
+ #: Seen from behind (mid-spin): no face, the wings on top of the back.
+ back: bool = False
+
+
+_C = _EmberCell
+_PERK = ("perk", "perk")
+_ARMS_UP = (((16, 32), (11, 27)), ((31, 32), (36, 27)))
+_ARMS_HIGH = (((16, 32), (10, 25)), ((31, 32), (37, 25)))
+_ARMS_RIM = (((16, 32), (13, 22)), ((31, 32), (34, 22)))
+_ARMS_PEEK = (((16, 32), (13, 19)), ((31, 32), (34, 19)))
+
+#: Every act frame by frame. Frame 0 and the last frame sit near the idle pose.
+_EMBER_ACT_CELLS: dict[str, tuple[_EmberCell, ...]] = {
+ #: Out of nowhere: a deep breath that lights the belly coal, a rear back,
+ #: a roaring jet of fire up and out to the left, then a proud smoke puff.
+ "fire_burst": (
+ _C(),
+ _C(eyes="wide", mouth="puff", stretch=1, wings=("half", "half"), fins=_PERK, glow=2),
+ _C(
+ dx=1,
+ dy=-1,
+ eyes="squint",
+ mouth="puff",
+ stretch=1,
+ wings=("up", "up"),
+ fins=_PERK,
+ tail=(2, 4, 1),
+ arms=_ARMS_UP,
+ glow=3,
+ ),
+ _C(
+ dx=-1,
+ eyes="look_left",
+ mouth="roar",
+ wings=("spread", "spread"),
+ fins=("flick",) * 2,
+ tail=(-1, 0, 1),
+ glow=3,
+ ),
+ _C(
+ dx=-1,
+ eyes="look_left",
+ mouth="roar",
+ wings=("spread", "spread"),
+ fins=("flick",) * 2,
+ tail=(0, 1, 1),
+ glow=2,
+ ),
+ _C(
+ dx=-1,
+ eyes="look_left",
+ mouth="roar",
+ wings=("half", "half"),
+ fins=("flick",) * 2,
+ tail=(1, 2, 1),
+ glow=1,
+ ),
+ _C(mouth="o", wings=("half", "half"), tail=(1, 1, 1)),
+ _C(eyes="happy", mouth="smile", fins=_PERK, cap=1, tail=(2, 2, 1)),
+ ),
+ #: A chain of smoke rings puffed out one after another, drifting up the
+ #: left side while Ember follows them with its eyes.
+ "smoke_rings": (
+ _C(),
+ _C(eyes="up_left", mouth="o"),
+ _C(eyes="up_left", mouth="puff"),
+ _C(eyes="up_left", mouth="o", tail=(1, 0, 1)),
+ _C(eyes="up_left", mouth="puff", tail=(2, 1, 1)),
+ _C(eyes="up_left", mouth="o", tail=(1, 0, 1)),
+ _C(eyes="happy", mouth="smile", fins=_PERK),
+ _C(eyes="look_left"),
+ ),
+ #: A big yawn with the arms up and the wings stretched wide, then a
+ #: little flutter to shake them out.
+ "wing_stretch": (
+ _C(),
+ _C(eyes="closed", mouth="o", stretch=1, wings=("half", "half")),
+ _C(
+ dy=-1,
+ eyes="closed",
+ mouth="wide",
+ stretch=1,
+ wings=("up", "up"),
+ fins=_PERK,
+ arms=_ARMS_UP,
+ ),
+ _C(
+ dy=-1,
+ eyes="closed",
+ mouth="wide",
+ stretch=1,
+ wings=("spread", "spread"),
+ fins=_PERK,
+ arms=_ARMS_HIGH,
+ tail=(2, 3, 1),
+ ),
+ _C(eyes="closed", mouth="half", wings=("flap", "flap")),
+ _C(dy=-1, mouth="closed", wings=("up", "up")),
+ _C(mouth="closed", wings=("flap", "flap")),
+ _C(eyes="happy", mouth="smile"),
+ ),
+ #: It spots its own spade, spins round after it (the back flashes past
+ #: twice) and ends up dizzy.
+ "tail_chase": (
+ _C(eyes="look_right", tail=(2, 2, 1)),
+ _C(dx=1, eyes="look_right", mouth="o", fins=_PERK, wings=("rest", "half"), tail=(2, 4, 1)),
+ _C(back=True, wings=("half", "half")),
+ _C(dx=-1, eyes="look_left", mouth="open", wings=("half", "rest"), tail=(2, 3, -1)),
+ _C(back=True, wings=("half", "half")),
+ _C(dx=1, eyes="look_right", mouth="open", wings=("rest", "half"), tail=(2, 3, 1)),
+ _C(dx=-1, eyes="dizzy", mouth="frown", fins=("droop", "flick")),
+ _C(eyes="dizzy", mouth="smile"),
+ ),
+ #: It yanks the eggshell down over its eyes, hides, peeks out left and
+ #: right, then pops out with the cap flying: boo!
+ "egg_peek": (
+ _C(),
+ _C(eyes="up_left", mouth="o", cap=2, arms=_ARMS_UP),
+ _C(
+ eyes="closed",
+ mouth="smile",
+ cap=None,
+ hood=20,
+ arms=_ARMS_RIM,
+ hands=((12, 20), (35, 20)),
+ ),
+ _C(
+ dx=1,
+ eyes="closed",
+ mouth="closed",
+ cap=None,
+ hood=20,
+ arms=_ARMS_RIM,
+ hands=((12, 20), (35, 20)),
+ ),
+ _C(
+ eyes="look_left",
+ mouth="closed",
+ cap=None,
+ hood=16,
+ arms=_ARMS_PEEK,
+ hands=((12, 16), (35, 16)),
+ ),
+ _C(
+ eyes="look_right",
+ mouth="closed",
+ cap=None,
+ hood=16,
+ arms=_ARMS_PEEK,
+ hands=((12, 16), (35, 16)),
+ ),
+ _C(
+ dy=-1, eyes="wide", mouth="open", cap=3, wings=("up", "up"), fins=_PERK, arms=_ARMS_HIGH
+ ),
+ _C(eyes="happy", mouth="smile", cap=1),
+ ),
+ #: Ah ... ah ... CHOO: a sneeze that blasts sparks and a soot cloud out
+ #: of the nostrils, then a startled, sooty face.
+ "sneeze": (
+ _C(),
+ _C(dy=-1, eyes="closed", mouth="o", stretch=1, fins=_PERK),
+ _C(dy=-2, eyes="squint", mouth="half", stretch=1, fins=_PERK, wings=("half", "half")),
+ _C(
+ dx=1,
+ dy=1,
+ eyes="squint",
+ mouth="cough",
+ stretch=-1,
+ fins=("flick",) * 2,
+ wings=("up", "up"),
+ tail=(2, 4, 1),
+ ),
+ _C(dx=1, eyes="wide", mouth="o", fins=_PERK, soot=True),
+ _C(eyes="wide", mouth="o", soot=True),
+ _C(eyes="look_right", mouth="closed", soot=True),
+ _C(eyes="happy", mouth="smile"),
+ ),
+}
+
+
+def _ember_act_pose(name: str, i: int) -> Pose:
+ c = _EMBER_ACT_CELLS[name][i]
+ return Pose("idle", i, dx=c.dx, dy=c.dy, eyes=c.eyes, mouth=c.mouth, stretch=c.stretch)
+
+
+def _ember_act_tail(f: Frame, sway: int, lift: int, side: int) -> None:
+ """The tail as in ``_ember_tail``; ``side`` -1 mirrors it to the left hip."""
+ tip = (41 + sway, 33 - lift)
+ tail = thick(polyline([(30, 42), (35, 43), (39, 41), (41 + sway // 2, 37 - lift // 2), tip]))
+ spade = from_rows(tip[0] - 2, tip[1] - 4, _EMBER_SPADE)
+ if side < 0:
+ tail, spade = mirrored(tail), mirrored(spade)
+ _ember_scales(f, tail, 1)
+ f.part(spade, _shade(spade, EMBER_SCALE, EMBER_SCALE_LIGHT, EMBER_SCALE_DARK, 1))
+
+
+def _ember_hood(f: Frame, rim: int) -> None:
+ """The eggshell pulled down over the head like a hood, jagged rim on row
+ ``rim``; the horns poke through it."""
+ hood = ellipse(CX, 15, 13.5, 11) & rect(0, 0, CELL - 1, rim)
+ hood -= {(x, rim) for x in range(CELL) if (x // 2) % 2}
+ f.part(hood, _shade(hood, EMBER_SHELL, FX_WHITE, EMBER_SHELL_DARK, 1))
+ f.paint({(16, 9), (17, 9), (31, 11), (26, 6), (21, 13)} & hood, EMBER_SHELL_SPOT)
+ for horn in (_EMBER_HORN, mirrored(_EMBER_HORN)):
+ f.part(horn, _shade(horn, EMBER_HORN, EMBER_HORN_LIGHT, EMBER_HORN_DARK, 1))
+
+
+def _draw_ember_back(f: Frame, pose: Pose, c: _EmberCell) -> None:
+ """Mid-spin, seen from behind: a ridge of golden plates down the back, the
+ wings on top, the tail curling out in front and no face."""
+ with f.offset(pose.dx, 0):
+ _ember_feet(f)
+ with f.offset(pose.dx, pose.dy):
+ body = ellipse(CX, 37, 10, 8)
+ _ember_scales(f, body)
+ f.paint({(x, y) for y in (31, 34, 37, 40) for x in (23, 24)}, EMBER_HORN)
+ tail = thick(polyline([(24, 42), (27, 45), (32, 45), (35, 42)]))
+ _ember_scales(f, tail, 1)
+ _ember_spade(f, 37, 39)
+ _ember_wing(f, c.wings[0], right=False)
+ _ember_wing(f, c.wings[1], right=True)
+ for k in range(2):
+ fin = polygon([(13.5, 14.5), _EMBER_FIN_TIPS["rest"], (12.5, 21.5)])
+ if k:
+ fin = mirrored(fin)
+ f.part(fin, shade(fin, EMBER_WING, dark=EMBER_WING_DARK, dark_depth=1))
+ for horn in (_EMBER_HORN, mirrored(_EMBER_HORN)):
+ f.part(horn, _shade(horn, EMBER_HORN, EMBER_HORN_LIGHT, EMBER_HORN_DARK, 1))
+ _ember_scales(f, ellipse(CX, 18, 12.5, 10.5))
+ f.paint({(x, y) for y in (21, 25) for x in (23, 24)}, EMBER_HORN)
+ f.glyph(20, 5, _EMBER_CAP, {"#": EMBER_SHELL, "o": EMBER_SHELL_SPOT})
+
+
+def _draw_ember_act(f: Frame, pose: Pose) -> None:
+ """An idle act's frame: the sitting dragon with the act's parts moved."""
+ c = _EMBER_ACT_CELLS[pose.act][pose.i]
+ if c.back:
+ _draw_ember_back(f, pose, c)
+ return
+ with f.offset(pose.dx, 0):
+ _ember_feet(f)
+ with f.offset(pose.dx, pose.dy):
+ _ember_act_tail(f, *c.tail)
+ _ember_wing(f, c.wings[0], right=False)
+ _ember_wing(f, c.wings[1], right=True)
+ _ember_scales(f, ellipse(CX, 37, 10, 8))
+ _ember_belly(f, CX, 38.5, 6, 5.5)
+ if c.glow:
+ _ember_belly_glow(f, c.glow) # the glow phase table starts 0, 1, 2, 3
+ arms = c.arms if c.arms is not None else (((16, 32), (14, 37)), ((31, 32), (33, 37)))
+ for shoulder, hand in arms:
+ _ember_arm(f, shoulder, hand)
+ _ember_head(f, pose, c.fins, cap=c.cap, soot=c.soot)
+ if c.hood:
+ _ember_hood(f, c.hood)
+ for hand in c.hands:
+ _ember_hand(f, *hand)
+
+
+def _ember_soot_puff(f: Frame, x: float, y: float, r: float, dark: bool) -> None:
+ """A speckled soot puff, darker while fresh, kept inside the cell."""
+ puff = _ember_in_cell(ellipse(x, y, r, r * 0.85))
+ if not puff:
+ return
+ color, fleck = (EMBER_SOOT_LIGHT, EMBER_SMOKE) if dark else (EMBER_SMOKE, EMBER_SMOKE_LIGHT)
+ f.part(
+ puff,
+ {
+ p: fleck if (p[0] - 1, p[1] - 1) not in puff or (p[0] + 2 * p[1]) % 7 == 0 else color
+ for p in puff
+ },
+ )
+
+
+#: The fire burst, per frame: the circles (x, y, r) whose union is the fire.
+#: A jet roars out of the mouth (Ember leans left), sweeps out and up the
+#: left side and blooms into a fireball in the top-left corner that rises,
+#: tears into tongues of flame and burns out.
+_EMBER_BURST: tuple[tuple[tuple[float, float, float], ...], ...] = (
+ (),
+ (),
+ # Embers at the lips: the fire is on its way.
+ ((20.5, 27.0, 1.6), (27.5, 27.0, 1.6)),
+ # The jet bursts out: a short, fat tongue with a leading ball.
+ (
+ (19.5, 26.5, 1.6),
+ (16.5, 26.0, 2.4),
+ (13.5, 25.0, 3.0),
+ (10.0, 23.0, 3.8),
+ (7.0, 20.5, 3.2),
+ ),
+ # Full blast: the jet sweeps up into a big fireball.
+ (
+ (19.5, 26.5, 1.8),
+ (16.5, 26.0, 2.8),
+ (13.5, 25.0, 3.6),
+ (10.5, 23.5, 4.2),
+ (8.0, 20.5, 4.6),
+ (7.0, 16.5, 5.0),
+ (8.5, 11.0, 6.4),
+ (4.0, 4.0, 1.6),
+ (13.0, 3.5, 1.4),
+ ),
+ # Still roaring, thinner at the lips; the fireball rises and tears.
+ (
+ (19.5, 26.5, 1.0),
+ (16.5, 26.0, 1.8),
+ (13.5, 25.0, 2.6),
+ (10.5, 23.5, 3.4),
+ (8.0, 20.5, 4.0),
+ (7.5, 15.5, 4.6),
+ (9.0, 9.5, 6.4),
+ (3.5, 3.0, 1.5),
+ (9.5, 2.5, 1.5),
+ (15.5, 4.5, 1.3),
+ ),
+ # Burnt out: the last licks of flame up in the corner.
+ ((4.5, 3.5, 1.3), (12.5, 2.5, 1.1)),
+ (),
+)
+#: The smoke the fireball leaves behind: (x, y, r, light) per frame.
+_EMBER_BURST_SMOKE: tuple[tuple[tuple[float, float, float, bool], ...], ...] = (
+ (),
+ (),
+ (),
+ (),
+ (),
+ (),
+ (
+ (8.5, 10.0, 4.6, False),
+ (14.5, 6.5, 2.8, False),
+ (4.0, 16.0, 2.8, True),
+ (11.0, 17.5, 2.2, True),
+ (17.0, 25.0, 1.5, True),
+ ),
+ ((7.5, 5.5, 3.0, True), (13.0, 3.5, 1.8, True)),
+)
+#: Sparks thrown off the fire, per frame: (x, y, hot).
+_EMBER_BURST_SPARKS: tuple[tuple[tuple[int, int, bool], ...], ...] = (
+ (),
+ (),
+ ((18, 29, True), (29, 29, False)),
+ ((14, 31, True), (4, 27, False), (17, 20, True), (2, 18, True)),
+ ((14, 32, False), (2, 27, True), (17, 14, True), (19, 7, False), (1, 13, False)),
+ ((11, 32, True), (1, 22, False), (18, 11, False), (20, 4, True), (3, 30, True)),
+ ((9, 34, False), (2, 26, True), (19, 12, False), (16, 2, True)),
+ ((8, 38, False), (3, 31, False)),
+)
+
+
+def _ember_fire_burst_fx(f: Frame, pose: Pose) -> None:
+ """The signature: a sniff that pulls the air in, embers at the lips, a
+ roaring jet that blooms into a fireball in the top-left corner, the smoke
+ it leaves behind, and a proud puff from the nostrils at the end."""
+ i = pose.i
+ if i == 1:
+ # The sniff: wisps of air drawn in towards the nostrils.
+ f.paint({(17, 20), (18, 21), (19, 21), (30, 20), (29, 21), (28, 21)}, EMBER_SMOKE_LIGHT)
+ if i == 2:
+ f.paint({(23, 19), (22, 18), (26, 19), (27, 18)}, EMBER_SMOKE)
+ for x, y, r, light in _EMBER_BURST_SMOKE[i]:
+ _ember_puff(f, x, y, r, EMBER_SMOKE_LIGHT if light else EMBER_SMOKE)
+ fire = _EMBER_BURST[i]
+ if fire:
+ with f.offset(pose.dx if i == 2 else 0, pose.dy if i == 2 else 0):
+ _ember_flame(f, [(x, y) for x, y, _r in fire], [r for _x, _y, r in fire])
+ if i == 7:
+ for side in (-1, 1):
+ _ember_puff(f, CX + side * 12, 22, 1.5)
+ for x, y, hot in _EMBER_BURST_SPARKS[i]:
+ _ember_spark(f, x, y, hot)
+
+
+#: Smoke rings: the frame each ring leaves the mouth, and the path a ring
+#: drifts along (one point per frame of age): out to the left, then up.
+_EMBER_RING_BORN = (1, 3, 5)
+_EMBER_RING_PATH = (
+ (16.5, 28.0),
+ (11.0, 27.0),
+ (6.5, 24.0),
+ (5.0, 19.0),
+ (5.5, 13.5),
+ (7.5, 8.5),
+ (10.5, 4.5),
+)
+
+
+def _ember_smoke_rings_fx(f: Frame, pose: Pose) -> None:
+ """A chain of fat smoke rings that grow as they rise and fade to a dither."""
+ for born in _EMBER_RING_BORN:
+ age = pose.i - born
+ if age < 0:
+ continue
+ cx, cy = _EMBER_RING_PATH[age]
+ rx = 2.0 + 0.75 * age
+ ry = rx * 0.75
+ hole = ellipse(cx, cy, rx - 1.6, ry - 1.6) if age else set()
+ ring = _ember_in_cell(ellipse(cx, cy, rx, ry) - hole)
+ if age < 3:
+ # Fresh smoke: dense, with a lighter top-left where it catches light.
+ colors = {
+ p: EMBER_SMOKE_LIGHT if (p[0] - 1, p[1]) not in ring and p[1] < cy else EMBER_SMOKE
+ for p in ring
+ }
+ f.paint_map(colors)
+ continue
+ if age >= 5:
+ ring = {p for p in ring if (p[0] + p[1]) % 2 == 0}
+ f.paint(ring, EMBER_SMOKE_LIGHT if age >= 4 else EMBER_SMOKE)
+
+
+def _ember_wing_stretch_fx(f: Frame, pose: Pose) -> None:
+ """A tear in each eye at the widest of the yawn, and little whoosh lines
+ under the wings as they flutter."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy):
+ if i == 3:
+ for x in (13, 34):
+ f.part({(x, 20), (x, 21)}, SWEAT)
+ if i in (4, 6):
+ f.paint(line(3, 27, 6, 27) | line(4, 29, 6, 29), ARC_FADE)
+ f.paint(line(41, 27, 44, 27) | line(41, 29, 43, 29), ARC_FADE)
+
+
+def _ember_tail_chase_fx(f: Frame, pose: Pose) -> None:
+ """Speed lines around the spin, then stars circling the dizzy head."""
+ i = pose.i
+ if i in (2, 3, 4):
+ f.paint(line(4, 31, 4, 38) | line(2, 33, 2, 36), ARC)
+ f.paint(line(43, 31, 43, 38) | line(45, 33, 45, 36), ARC)
+ if i == 1:
+ f.paint(line(45, 26, 45, 29), ARC_FADE) # the tail's whoosh
+ if i in (6, 7):
+ spots = ((9, 7), (38, 5)) if i == 6 else ((13, 3), (35, 8))
+ for x, y in spots:
+ f.glyph(x - 1 + pose.dx, y - 1, _SPARK_S, _SPARK_PALETTE)
+
+
+def _ember_egg_peek_fx(f: Frame, pose: Pose) -> None:
+ """A giggle while it hides, and sparkles when it pops out: boo!"""
+ i = pose.i
+ if i == 3:
+ f.paint({(39, 10), (40, 9), (41, 10), (42, 9)}, ARC)
+ f.paint({(6, 10), (7, 9), (8, 10), (9, 9)}, ARC)
+ if i == 6:
+ fx_sparkles(f, 1, ((6, 10, 0), (41, 8, 0)))
+ f.paint(line(23, 0, 23, 1) | line(18, 1, 17, 0) | line(29, 1, 30, 0), ARC)
+
+
+#: The sneeze cloud per frame: (x, y, r, dark) puffs drifting up and right.
+_EMBER_SNEEZE: tuple[tuple[tuple[float, float, float, bool], ...], ...] = (
+ (),
+ (),
+ (),
+ ((34.0, 27.0, 3.8, True), (41.0, 24.5, 4.6, True), (40.0, 32.5, 3.4, False)),
+ ((38.0, 20.5, 5.2, True), (44.0, 15.5, 3.4, False), (32.5, 26.0, 2.6, False)),
+ ((40.0, 13.5, 4.6, False), (45.0, 9.5, 2.6, False), (35.0, 19.5, 2.0, False)),
+ ((42.0, 7.5, 3.6, False), (37.5, 11.5, 1.8, False)),
+ ((43.0, 4.0, 2.2, False),),
+)
+_EMBER_SNEEZE_SPARKS: tuple[tuple[tuple[int, int, bool], ...], ...] = (
+ (),
+ (),
+ ((22, 21, True),),
+ ((33, 21, True), (39, 23, True), (45, 25, False), (40, 33, True), (34, 32, False)),
+ ((44, 30, False), (37, 33, True), (46, 18, True)),
+ ((42, 36, False), (30, 33, False)),
+ ((40, 40, False),),
+ (),
+)
+
+
+def _ember_sneeze_fx(f: Frame, pose: Pose) -> None:
+ """The nostrils twitch, flare, and CHOO: sparks and soot burst out to the
+ right and the cloud drifts away."""
+ i = pose.i
+ with f.offset(pose.dx, pose.dy):
+ if i == 1:
+ f.paint({(21, 21), (26, 21)}, EMBER_SMOKE_LIGHT)
+ if i == 2:
+ f.paint({(20, 21), (21, 20), (26, 20), (27, 21)}, ARC)
+ if i == 3:
+ f.glyph(27, 20, _SPARK_L, _SPARK_PALETTE)
+ for x, y, r, dark in _EMBER_SNEEZE[i]:
+ _ember_soot_puff(f, x, y, r, dark)
+ for x, y, hot in _EMBER_SNEEZE_SPARKS[i]:
+ _ember_spark(f, x, y, hot)
+
+
+def _ember_act(name: str, frames: int, fps: int, fx: Effect) -> IdleAct:
+ return IdleAct(name, frames, fps, lambda i: _ember_act_pose(name, i), fx)
+
+
+EMBER_ACTS = (
+ _ember_act("fire_burst", 8, 9, _ember_fire_burst_fx),
+ _ember_act("smoke_rings", 8, 7, _ember_smoke_rings_fx),
+ _ember_act("wing_stretch", 8, 8, _ember_wing_stretch_fx),
+ _ember_act("tail_chase", 8, 10, _ember_tail_chase_fx),
+ _ember_act("egg_peek", 8, 6, _ember_egg_peek_fx),
+ _ember_act("sneeze", 8, 8, _ember_sneeze_fx),
+)
+
+
EMBER = PetDesign(
id="ember",
name="Ember",
@@ -5022,9 +7083,11 @@ EMBER = PetDesign(
"searching": _ember_searching_fx,
"held": _ember_held_fx,
},
+ acts=EMBER_ACTS,
)
-PETS: tuple[PetDesign, ...] = (GIGI, MISO, BREW, BOLT, MOCHI, SHELLY, PIP, EMBER)
+
+PETS: tuple[PetDesign, ...] = (GIGI, MISO, BREW, BOLT, MOCHI, SHELLY, EMBER)
# ---------------------------------------------------------------------------
@@ -5050,6 +7113,30 @@ def breathe(body: Image.Image, stretch: int, waist: int) -> Image.Image:
return out
+def render_act_frame(pet: PetDesign, act: IdleAct, i: int) -> Image.Image:
+ """Frame ``i`` of an idle act: the act's pose through the pet's own drawing."""
+ pose = replace(act.pose(i), state="idle", i=i, act=act.name)
+ body = Frame()
+ pet.draw(body, pose)
+ image = breathe(body.image(), pose.stretch, pet.waist + pose.dy)
+ if pet.post is not None:
+ image = pet.post(image, pose)
+ if act.fx is not None:
+ fx = Frame()
+ act.fx(fx, pose)
+ image.alpha_composite(fx.image())
+ return image
+
+
+def build_acts_sheet(pet: PetDesign) -> Image.Image:
+ """One row per idle act, in declaration order."""
+ sheet = Image.new("RGBA", (CELL * MAX_FRAMES_PER_STATE, CELL * len(pet.acts)), (0, 0, 0, 0))
+ for row, act in enumerate(pet.acts):
+ for i in range(act.frames):
+ sheet.paste(render_act_frame(pet, act, i), (i * CELL, row * CELL))
+ return sheet
+
+
def render_frame(pet: PetDesign, state: str, i: int) -> Image.Image:
pose = pet.pose(state, i)
body = Frame()
@@ -5076,10 +7163,14 @@ def build_sheet(pet: PetDesign) -> Image.Image:
return sheet
+#: File name of a pet's idle-act sheet.
+ACTS_SHEET = "acts.png"
+
+
def build_manifest(pet: PetDesign) -> dict:
counts = pet.counts()
fps = {**FPS, **(pet.fps or {})}
- return {
+ manifest = {
"format": PET_FORMAT,
"id": pet.id,
"name": pet.name,
@@ -5090,6 +7181,13 @@ def build_manifest(pet: PetDesign) -> dict:
state: _animation(state, row, counts, fps) for row, state in enumerate(PET_STATES)
},
}
+ if pet.acts:
+ manifest["acts_sheet"] = ACTS_SHEET
+ manifest["acts"] = {
+ act.name: {"row": row, "frames": act.frames, "fps": act.fps, "loop": False}
+ for row, act in enumerate(pet.acts)
+ }
+ return manifest
def _animation(state: str, row: int, counts: Mapping[str, int], fps: Mapping[str, int]) -> dict:
@@ -5161,6 +7259,9 @@ def build_all(out_dir: Path) -> list[Path]:
save_png(build_sheet(pet), folder / "sheet.png")
save_json(build_manifest(pet), folder / "pet.json")
written += [folder / "sheet.png", folder / "pet.json"]
+ if pet.acts:
+ save_png(build_acts_sheet(pet), folder / ACTS_SHEET)
+ written.append(folder / ACTS_SHEET)
folder = out_dir / "template"
folder.mkdir(parents=True, exist_ok=True)
sheet, manifest = build_template()
diff --git a/tests/unit/ui/pets/test_builtin_pets.py b/tests/unit/ui/pets/test_builtin_pets.py
index ed40743551..2fa531cfe0 100644
--- a/tests/unit/ui/pets/test_builtin_pets.py
+++ b/tests/unit/ui/pets/test_builtin_pets.py
@@ -17,7 +17,7 @@ from jarvis.ui.pets.states import DEFAULT_PET_ID, PET_STATES
REPO_ROOT = Path(__file__).resolve().parents[4]
BUILD_SCRIPT = REPO_ROOT / "scripts" / "pets" / "build_pets.py"
PACKAGE_DIR = REPO_ROOT / "jarvis" / "ui" / "pets"
-EXPECTED_PETS = ("gigi", "miso", "brew", "bolt", "mochi", "shelly", "pip", "ember")
+EXPECTED_PETS = ("gigi", "miso", "brew", "bolt", "mochi", "shelly", "ember")
def _builder() -> ModuleType:
@@ -89,6 +89,10 @@ def test_committed_pet_matches_the_generator(generated: Path, pet_id: str) -> No
assert (ours / "pet.json").read_text(encoding="utf-8") == (fresh / "pet.json").read_text(
encoding="utf-8"
)
+ if (fresh / "acts.png").exists():
+ assert _pixels(ours / "acts.png") == _pixels(fresh / "acts.png"), (
+ f"{pet_id}: run `python scripts/pets/build_pets.py` and commit the result"
+ )
def test_committed_template_matches_the_generator(generated: Path) -> None:
@@ -117,3 +121,18 @@ def test_the_renderer_conventions_hold(pet_id: str) -> None:
talking = pack.frames["talking"]
for before, after in zip(talking, talking[1:], strict=False):
assert before.tobytes() != after.tobytes()
+
+
[email protected]("pet_id", EXPECTED_PETS)
+def test_every_builtin_pet_has_idle_acts(pet_id: str) -> None:
+ """Now and then an idle pet does something on its own (docs/pets.md)."""
+ pack = load_pet(builtin_root() / pet_id, builtin=True)
+ assert 4 <= len(pack.acts) <= 12
+ idle = pack.frames["idle"][0].tobytes()
+ for name, spec in pack.manifest.acts.items():
+ assert not spec.loop
+ frames = pack.acts[name]
+ assert len(frames) == spec.frames >= 2
+ for frame in frames:
+ assert frame.getchannel("A").getbbox() is not None, f"{name} has an empty frame"
+ assert any(frame.tobytes() != idle for frame in frames), f"{name} never moves"
diff --git a/tests/unit/ui/pets/test_loader.py b/tests/unit/ui/pets/test_loader.py
index a1b22080a3..eb9ee5f337 100644
--- a/tests/unit/ui/pets/test_loader.py
+++ b/tests/unit/ui/pets/test_loader.py
@@ -197,3 +197,40 @@ def test_list_pets_orders_default_first_and_skips_broken(tmp_path: Path, user_pe
def test_list_pets_without_custom_folder(tmp_path: Path) -> None:
assert all(m.builtin for m in list_pets(data_dir=tmp_path / "missing"))
+
+
+def test_idle_acts_load_from_their_own_sheet(tmp_path: Path) -> None:
+ folder = _write_pet(tmp_path / "pets" / USER_ID, pet_id=USER_ID, sheet=_two_row_sheet())
+ acts = Image.new("RGBA", (96, 64), (0, 0, 0, 0))
+ acts.paste((200, 10, 10, 255), (0, 0, 32, 32)) # "wave" frame 0
+ acts.paste((10, 200, 10, 128), (32, 0, 64, 32)) # "wave" frame 1, half alpha
+ acts.paste((10, 10, 200, 255), (0, 32, 32, 64)) # "hop" frame 0
+ acts.save(folder / "acts.png")
+ manifest = json.loads((folder / "pet.json").read_text(encoding="utf-8"))
+ manifest["acts_sheet"] = "acts.png"
+ manifest["acts"] = {
+ "wave": {"row": 0, "frames": 2, "fps": 8},
+ "hop": {"row": 1, "frames": 1, "fps": 8},
+ }
+ (folder / "pet.json").write_text(json.dumps(manifest), encoding="utf-8")
+
+ pack = load_pet(folder, builtin=False)
+ assert list(pack.acts) == ["wave", "hop"]
+ assert len(pack.acts["wave"]) == 2 and len(pack.acts["hop"]) == 1
+ assert pack.acts["wave"][0].getpixel((3, 3)) == (200, 10, 10, 255)
+ assert pack.acts["wave"][1].getpixel((3, 3)) == (10, 200, 10, 255) # alpha made binary
+ assert pack.acts["hop"][0].size == (32, 32)
+
+
+def test_a_missing_acts_sheet_breaks_the_pet(tmp_path: Path) -> None:
+ folder = _write_pet(tmp_path / "pets" / USER_ID, pet_id=USER_ID, sheet=_two_row_sheet())
+ manifest = json.loads((folder / "pet.json").read_text(encoding="utf-8"))
+ manifest["acts_sheet"] = "acts.png"
+ manifest["acts"] = {"wave": {"row": 0, "frames": 2, "fps": 8}}
+ (folder / "pet.json").write_text(json.dumps(manifest), encoding="utf-8")
+ with pytest.raises(PetManifestError):
+ load_pet(folder, builtin=False)
+
+
+def test_a_pet_without_acts_has_none(user_pet: Path) -> None:
+ assert dict(load_pet(user_pet, builtin=False).acts) == {}
diff --git a/tests/unit/ui/pets/test_manifest.py b/tests/unit/ui/pets/test_manifest.py
index ab51afe79a..02b3310190 100644
--- a/tests/unit/ui/pets/test_manifest.py
+++ b/tests/unit/ui/pets/test_manifest.py
@@ -11,6 +11,7 @@ from jarvis.ui.pets.manifest import (
MAX_NAME_CHARS,
AnimationSpec,
PetManifestError,
+ check_act_cells,
check_cells,
check_sheet_size,
parse_manifest,
@@ -210,3 +211,58 @@ def test_an_accent_needs_a_looping_row() -> None:
animations["success"].update({"accent_frames": 1, "accent_every": 2})
with pytest.raises(PetManifestError):
parse_manifest(_data(animations=animations), builtin=True)
+
+
+# --- Idle acts -------------------------------------------------------------------
+
+
+def _acts(**overrides: object) -> dict:
+ acts: dict = {
+ "fire": {"row": 0, "frames": 6, "fps": 8},
+ "yawn": {"row": 1, "frames": 4, "fps": 6},
+ }
+ acts.update(overrides)
+ return acts
+
+
+def test_idle_acts_are_optional_one_shots_on_their_own_sheet() -> None:
+ manifest = parse_manifest(_data(acts=_acts(), acts_sheet="acts.png"), builtin=True)
+ assert list(manifest.acts) == ["fire", "yawn"]
+ assert manifest.acts["fire"] == AnimationSpec(row=0, frames=6, fps=8, loop=False)
+ assert manifest.acts_sheet == "acts.png"
+ again = parse_manifest(manifest.to_json(), builtin=True)
+ assert again.acts == manifest.acts and again.acts_sheet == "acts.png"
+ plain = parse_manifest(_data(), builtin=True)
+ assert not plain.acts and plain.acts_sheet is None
+ assert "acts" not in plain.to_json()
+
+
+ "overrides",
+ [
+ {"acts": _acts()}, # no sheet
+ {"acts_sheet": "acts.png"}, # no acts
+ {"acts": {}, "acts_sheet": "acts.png"},
+ {"acts": _acts(), "acts_sheet": "sheet.png"}, # the state sheet
+ {"acts": _acts(), "acts_sheet": "../acts.png"},
+ {"acts": {"Fire!": {"row": 0, "frames": 2, "fps": 8}}, "acts_sheet": "acts.png"},
+ {"acts": {"fire": {"row": 0, "frames": 2, "fps": 8, "loop": True}}, "acts_sheet": "a.png"},
+ {"acts": {"fire": {"row": 0, "frames": 9, "fps": 8}}, "acts_sheet": "acts.png"},
+ {
+ "acts": {f"a{k}": {"row": k, "frames": 2, "fps": 8} for k in range(13)},
+ "acts_sheet": "a.png",
+ },
+ ],
+)
+def test_broken_idle_acts_are_rejected(overrides: dict) -> None:
+ with pytest.raises(PetManifestError):
+ parse_manifest(_data(**overrides), builtin=True)
+
+
+def test_an_act_must_fit_its_sheet() -> None:
+ manifest = parse_manifest(_data(acts=_acts(), acts_sheet="acts.png"), builtin=True)
+ check_act_cells(manifest, 48 * 6, 48 * 2)
+ with pytest.raises(PetManifestError):
+ check_act_cells(manifest, 48 * 5, 48 * 2)
+ with pytest.raises(PetManifestError):
+ check_act_cells(manifest, 48 * 6, 48)
diff --git a/tests/unit/ui/test_pet_overlay_renderer.py b/tests/unit/ui/test_pet_overlay_renderer.py
index 4fb10ad2d1..9366f4d4e3 100644
--- a/tests/unit/ui/test_pet_overlay_renderer.py
+++ b/tests/unit/ui/test_pet_overlay_renderer.py
@@ -442,3 +442,94 @@ def test_garbage_levels_are_ignored() -> None:
renderer.feed_level(float("nan"), clock.now)
renderer.feed_level("loud", clock.now) # type: ignore[arg-type]
assert renderer.frame_key()[-1] in range(4)
+
+
+# --- idle acts ----------------------------------------------------------------
+
+
+class _ActManifest(_Manifest):
+ def __init__(self) -> None:
+ super().__init__(48, _Pack().manifest._specs)
+ self.acts = {"wave": _Spec(0, 3, 10, False), "hop": _Spec(1, 2, 10, False)}
+
+
+class _ActPack(_Pack):
+ def __init__(self) -> None:
+ super().__init__()
+ self.manifest = _ActManifest()
+ self.acts = {
+ name: tuple(
+ Image.new("RGBA", (48, 48), (200, 40 * i, spec.row, 255))
+ for i in range(spec.frames)
+ )
+ for name, spec in self.manifest.acts.items()
+ }
+
+
+class _Rng:
+ """Picks the low end of every range and the first allowed act."""
+
+ def uniform(self, low: float, high: float) -> float:
+ return low
+
+ def choice(self, options: list[str]) -> str:
+ return options[0]
+
+
+def _act_renderer(clock: _Clock) -> pr.PetRenderer:
+ renderer, _ = _renderer(clock, loader=_Loader({"fake": _ActPack()}), rng=_Rng())
+ return renderer
+
+
+def test_an_idle_pet_plays_an_act_after_a_while_and_returns_to_idle() -> None:
+ clock = _Clock()
+ renderer = _act_renderer(clock)
+ first_delay, gap = pr.ACT_FIRST_DELAY_S[0], pr.ACT_GAP_S[0]
+ assert renderer.frame_key()[2] == "idle"
+ clock.now += first_delay - 0.01
+ assert renderer.frame_key()[2] == "idle"
+ clock.now += 0.02
+ assert renderer.frame_key()[2:] == ("act:wave", 0)
+ clock.now += 0.1
+ assert renderer.frame_key()[2:] == ("act:wave", 1)
+ clock.now += 0.25 # past the act's 0.3 s
+ assert renderer.frame_key()[2] == "idle"
+ clock.now += gap + 0.01
+ # Never the same act twice in a row.
+ assert renderer.frame_key()[2:] == ("act:hop", 0)
+
+
+def test_any_other_state_cancels_the_act() -> None:
+ clock = _Clock()
+ renderer = _act_renderer(clock)
+ clock.now += pr.ACT_FIRST_DELAY_S[0] + 0.01
+ assert renderer.frame_key()[2] == "act:wave"
+ renderer.on_mode("listen")
+ assert renderer.frame_key()[2] == "listening"
+
+
+def test_the_overlay_sleeps_until_the_act_is_due_and_through_its_end() -> None:
+ clock = _Clock()
+ renderer = _act_renderer(clock)
+ clock.now += pr.ACT_FIRST_DELAY_S[0] - 0.1
+ assert renderer.next_frame_delay_ms() <= 105 # the act is due in 0.1 s
+ clock.now += 0.1
+ renderer.frame_key()
+ clock.now += 0.25 # on the act's last frame
+ assert renderer.next_frame_delay_ms() <= 52 # until the act ends, not "never"
+
+
+def test_act_frames_are_scaled_with_the_states() -> None:
+ clock = _Clock()
+ renderer = _act_renderer(clock)
+ clock.now += pr.ACT_FIRST_DELAY_S[0] + 0.01
+ frame = renderer.render()
+ assert frame.size == renderer.size
+ assert frame.getpixel((0, 0))[0] == 200
+
+
+def test_a_pet_without_acts_just_idles() -> None:
+ clock = _Clock()
+ renderer, _ = _renderer(clock)
+ clock.now += 120.0
+ assert renderer.frame_key()[2] == "idle"
diff --git a/ui/orb/pet_renderer.py b/ui/orb/pet_renderer.py
index 9d33e98c18..09a9b6a8a3 100644
--- a/ui/orb/pet_renderer.py
+++ b/ui/orb/pet_renderer.py
@@ -14,6 +14,12 @@ an idle pet costs next to nothing). So this renderer works the other way round:
frame boundary or the next state change the state machine will make on its
own (a one-shot ending, the pet falling asleep).
+Idle acts: while the pet idles, it now and then plays one of its acts (a yawn,
+a stretch, a puff of fire) once and goes back to idling — after a random pause
+of :data:`ACT_FIRST_DELAY_S` once it starts idling, then every
+:data:`ACT_GAP_S`, never the same act twice in a row. Any other state cancels
+a running act; the overlay's frame timer covers the wait, so nothing extra runs.
+
Talking follows the voice: the talking row is drawn closed → widest, and while
a live output level arrives the frame is picked from that level (smoothed,
bucketed — an unchanged level gives an unchanged key, so no repaint). Without a
@@ -29,6 +35,7 @@ from __future__ import annotations
import logging
import math
+import random
import sys
import time
from collections.abc import Callable, Hashable, Mapping, Sequence
@@ -73,6 +80,13 @@ LEVEL_OPEN_SPAN = 0.45
#: Source pixels kept around the cropped figure (sparkles may touch the edge).
_CROP_MARGIN = 1
+#: Seconds of idling before the first idle act, as a random ``(low, high)`` range.
+ACT_FIRST_DELAY_S = (6.0, 18.0)
+#: Seconds between the end of one idle act and the next, as a random range.
+ACT_GAP_S = (14.0, 40.0)
+#: Frame-key prefix of an idle act (an act and a state can share a name).
+_ACT_KEY = "act:"
+
_ColorKey = tuple[int, int, int]
@@ -267,8 +281,16 @@ class PetRenderer:
loader: Callable[[str], Any] | None = None,
to_color_key: Callable[[Image.Image, int, _ColorKey], Image.Image] | None = None,
machine: Any | None = None,
+ rng: random.Random | None = None,
) -> None:
self._clock = clock
+ self._rng = rng or random.Random() # noqa: S311 — a pet's whim, not crypto
+ #: The idle stretch the act schedule belongs to (its start time).
+ self._idle_epoch: float | None = None
+ #: The running act ``(name, started_at)``, and when the next one is due.
+ self._act: tuple[str, float] | None = None
+ self._act_due = math.inf
+ self._last_act: str | None = None
self._color_key = tuple(int(c) for c in color_key)
self._dpi_ratio = float(dpi_ratio)
self._pet_scale = float(pet_scale)
@@ -320,13 +342,21 @@ class PetRenderer:
def _rescale(self) -> None:
self._frames = {}
+ self._act_names: tuple[str, ...] = ()
+ self._act = None
self._blank = None
pack = self._pack
if pack is None:
self._use_strip_only_size()
return
edge = int(pack.manifest.frame_size)
- source: Mapping[str, Any] = pack.frames
+ acts: Mapping[str, Any] = getattr(pack, "acts", None) or {}
+ # Act frames join the crop (a flame may reach past the idle figure)
+ # and are scaled with the states, under a prefixed key.
+ source: Mapping[str, Any] = {
+ **pack.frames,
+ **{_ACT_KEY + str(name): seq for name, seq in acts.items()},
+ }
try:
crop, (idle_w, idle_h) = figure_crop(source, edge)
factor = pixel_factor(max(idle_w, idle_h), self._dpi_ratio, self._pet_scale)
@@ -353,6 +383,7 @@ class PetRenderer:
self._use_strip_only_size()
return
self._frames = frames
+ self._act_names = tuple(name for name in acts if frames.get(_ACT_KEY + name))
self._factor = factor
self._size = ((crop[2] - crop[0]) * factor, (crop[3] - crop[1]) * factor)
self._figure_width = idle_w * factor
@@ -443,9 +474,48 @@ class PetRenderer:
# -- frame selection -------------------------------------------------
+ def _idle_act(self, state: str) -> tuple[str, Any, int, float] | None:
+ """The idle act on screen now, starting or ending one as its time comes.
+
+ Returns ``(frame key, spec, frame index, elapsed)`` while an act plays,
+ else ``None``. Only an idling pet with acts ever plays one.
+ """
+ if state != "idle" or not self._act_names:
+ self._idle_epoch = None
+ self._act = None
+ return None
+ now = float(self._clock())
+ epoch = float(self._machine.state_started_at())
+ if epoch != self._idle_epoch:
+ self._idle_epoch = epoch
+ self._act = None
+ self._act_due = epoch + self._rng.uniform(*ACT_FIRST_DELAY_S)
+ acts = self._pack.manifest.acts
+ if self._act is not None:
+ name, started = self._act
+ spec = acts[name]
+ if now - started >= spec.frames / float(spec.fps):
+ self._act = None
+ self._act_due = now + self._rng.uniform(*ACT_GAP_S)
+ if self._act is None and now >= self._act_due:
+ choices = [n for n in self._act_names if n != self._last_act] or list(self._act_names)
+ name = self._rng.choice(choices)
+ self._act = (name, now)
+ self._last_act = name
+ if self._act is None:
+ return None
+ name, started = self._act
+ spec = acts[name]
+ elapsed = max(0.0, now - started)
+ return _ACT_KEY + name, spec, frame_index(elapsed, spec.frames, spec.fps, False), elapsed
+
def _current(self) -> tuple[str, Any, int, float, bool]:
"""(resolved state, spec, frame index, elapsed seconds, level-driven) for now."""
state = self.state()
+ act = self._idle_act(state)
+ if act is not None:
+ key, spec, index, elapsed = act
+ return key, spec, index, elapsed, False
resolved, spec = self._pack.manifest.spec_for(state)
resolved = str(resolved)
sequence = self._frames.get(resolved) or self._frames.get(state) or ()
@@ -490,6 +560,11 @@ class PetRenderer:
boundary = seconds_to_next_frame(elapsed, frames, float(spec.fps), loop)
if boundary is not None:
waits.append(boundary)
+ if resolved.startswith(_ACT_KEY):
+ # The act's last frame holds until the act is over.
+ waits.append(max(0.0, spec.frames / float(spec.fps) - elapsed))
+ elif self._idle_epoch is not None and math.isfinite(self._act_due):
+ waits.append(max(0.0, self._act_due - float(self._clock())))
if not waits:
return MAX_FRAME_DELAY_MS
# A hair past the boundary, so the tick lands on the new frame rather