Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(video): a foot the set alignment names by too small a margin is left for whoever looks — low-margin

Soohong Kim2103a691b3c7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 716218d..7e023eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,12 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
+## Unreleased (v2.34.0) - A foot the set alignment names by too small a margin is left for whoever looks
+
+- **Output change: a side or diagonal loop whose shade parts its two strikes by less than 0.025 in luma is no longer named** (`video-cycle-align`, `video-set --align-cycles`; `align.SHADE_MARGIN`, was 0.015). The shade cue (the far leg drawn darker) named a foot whenever the strikes differed by 0.015; on drawn walks checked by eye it named feet wrong at margins under the new bar and right above it. A foot named wrong is not asked about — the loop ships half a cycle off — so a margin under the bar now leaves the foot unnamed: the loop starts on its larger strike with `start_foot: null`, is listed under the report's `unnamed_feet` with its two candidate strike frames, and is told back with `--foot <loop>=left|right` (`video-set --align-foot`) by a person or a vision call. Its frames, strip, GIF and WebP are those of its larger strike as before; only who named the foot changes. Front and back loops (the depth cue, 1 % of the body's height) and every loop whose margin clears the bar come out byte for byte as they were. [docs/loop-repair.md](docs/loop-repair.md#4-one-cycle-for-a-direction-set--video-cycle-align-video-set---align-cycles-auto).
+- **`foot_why` of a margin too small starts `low-margin`**, with the margin, the cue and the bar (`low-margin: the two strikes differ by 0.0235 in shade, under the 0.025 it takes to name a foot`; `align.LOW_MARGIN`), in place of `the two strikes look alike in shade (…)`, for both cues — in the loop row, `unnamed_feet`, the warning, and `foot_unnamed_why` once told.
+- **`tests/video/test_cycle_align_foot_margin.py`** draws the side walker with its far leg 3 levels darker (margin 0.0235: named under 0.015, unnamed now — listed, warned, told back by `--foot`) and 4 levels darker (0.0314: named as before).
+
## v2.33.0 - A horse's sheet does not swing its arms, and it does not strike with its hands
- **Fix: the sheet rows `prepare` writes gave every body a person's arms, shoulders and hands.** 2.32.0's body plan reached the clip's walk, idle and still but not the rows an image model draws a sheet from: the walk and run rows moved "body, arm, leg, hair, and prop", the front and three-quarter-front walks "alternating leg, arm, shoulder", the diagonal runs traded "foot-contact phases" of "the left and right legs", the wave was "arm pose only: arm down, arm raised, hand tilted" (default action "friendly hand wave gesture"), every row's anchor lock spent its motion on "arm counter-swing" and turned "the body, feet, shoulders", and a diagonal row read its facing by "shoulder overlap, hand/foot placement". A horse's walk sheet came with arms.
diff --git a/SKILL.md b/SKILL.md
index 7a5f98f..a7e0ecd 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -102,7 +102,7 @@ hold the arms still, and check the loop with `handed-check --state walk`.
| Continue or edit an existing clip | `video-extend`, `video-edit` | [video](docs/video.md) |
| Grok video sprites | `video-set` | [video-pipeline](docs/video-pipeline.md) |
| A soft part of a walk loop follows the body (a chest, a belly): an ellipse in the first cell, after `video-cycle-align` | `video-follow` | [video-pipeline](docs/video-pipeline.md#6-follow-through--video-follow) |
-| Video sprites from a clip your agent makes with a connected video MCP (ZCRE, 지크) | `video-canvas`, `video-prompt --no-last-frame`, the agent's own MCP tools (quote, user approval, generate, save the mp4), then `video-frames` and `video-loop` (a walk or run with `--anchor motion-auto`, which holds its size), and for a walk or run cut in two or more directions `video-cycle-align --view …` over their loop directories (a set it stops on a loop that may hold two cycles: look at that loop, count its strides, and pass `--cycles <loop>=<k>`; a loop the report lists under `unnamed_feet` — its view could not tell the feet apart: look at its first candidate frame, say which own foot lands there, and align again with `--foot <loop>=left|right`). `video-set` is not run on this route, so the set stage it runs by default (`--align-cycles auto`) is yours to run. sprite-gen never calls the MCP. Walk, run and jump only: ZCRE's `grok-imagine-video-1.5` has no end frame, so idle, attack and diagonal walks are refused unless `--unpinned` | [video-pipeline](docs/video-pipeline.md#a-clip-from-a-video-mcp-on-your-agent--zcre) |
+| Video sprites from a clip your agent makes with a connected video MCP (ZCRE, 지크) | `video-canvas`, `video-prompt --no-last-frame`, the agent's own MCP tools (quote, user approval, generate, save the mp4), then `video-frames` and `video-loop` (a walk or run with `--anchor motion-auto`, which holds its size), and for a walk or run cut in two or more directions `video-cycle-align --view …` over their loop directories (a set it stops on a loop that may hold two cycles: look at that loop, count its strides, and pass `--cycles <loop>=<k>`; a loop the report lists under `unnamed_feet` — its view could not tell the feet apart, or only by too small a margin (`low-margin`): look at its first candidate frame, say which own foot lands there, and align again with `--foot <loop>=left|right`). `video-set` is not run on this route, so the set stage it runs by default (`--align-cycles auto`) is yours to run. sprite-gen never calls the MCP. Walk, run and jump only: ZCRE's `grok-imagine-video-1.5` has no end frame, so idle, attack and diagonal walks are refused unless `--unpinned` | [video-pipeline](docs/video-pipeline.md#a-clip-from-a-video-mcp-on-your-agent--zcre) |
| Ordinary image or edit | `gen --provider codex` or `gen --provider grok` (subscription routes) | [gen](docs/gen.md) |
| Image generation with no login available (server, container, SaaS) | `gen --provider openai` — server/SaaS route on `OPENAI_API_KEY`, **billed per call**, never a default or a fallback | [gen](docs/gen.md#subscription-first--openai-is-named-or-it-does-not-run) |
| Base and direction anchors | `anchor` | [directional-anchor-workflow](docs/directional-anchor-workflow.md) |
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 72b731c..8a5bfd4 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -433,10 +433,16 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
The cue must follow the step — its once-a-cycle swing (first harmonic) at least a quarter of
its spread over the cycle, or it is the drawing's own flicker — and, averaged over each strike
- frame and its two neighbours, the two strikes must differ by 0.015 in luma (shade) or 1 % of
- the body's height (depth); otherwise the foot is not named. A view seen from behind a diagonal
- can shade its legs too evenly for this, and is then left unnamed rather than guessed. A loop row carries `view`, `start_foot` and `foot` (the cue, the strikes, their values,
- the margin, the feet); a loop whose foot is not named starts on its larger strike with
+ frame and its two neighbours, the two strikes must differ by 0.025 in luma (shade,
+ `align.SHADE_MARGIN`) or 1 % of the body's height (depth, `align.FOOT_MARGIN`); otherwise the
+ foot is not named and `foot_why` starts **`low-margin`** (with the margin and the bar). A view seen
+ from behind a diagonal can shade its legs too evenly for this, and is then left unnamed rather than
+ guessed. The shade's bar is set from drawn walks whose feet were checked by eye: it lies above the
+ margins at which the shade named a foot wrong and under those at which it named one right. A foot
+ named wrong turns the loop half a cycle off with nobody asked; a foot left unnamed costs one look
+ (a person or a vision call, `unnamed_feet` below), so a margin near the bar is left for the look.
+ A loop row carries `view`, `start_foot` and `foot` (the cue, the strikes, their values, the
+ margin, the feet); a loop whose foot is not named starts on its larger strike with
`start_foot: null` and `foot_why`, and the report's `warnings` say so — a set whose loops do
not all name their foot may not start on one foot. Without `--view` no foot is named and the
report says that once. A character drawn without shading on the far leg leaves its side and
@@ -445,7 +451,9 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
cue), `"given"` (`--foot`, below) or `null` (nobody), and `strikes` — its two strikes as frames of
the rebuilt `cycle/`, the larger first.
- **A foot the engine cannot name is told, one loop at a time**: each loop whose foot is not named
- is listed in the report's **`unnamed_feet`** — per loop `dir`, `name`, `view`, `foot_why`,
+ — its view's cue does not follow the step, parts the strikes by less than the margin
+ (`low-margin`), or there are no legs to read — is listed in the report's **`unnamed_feet`**:
+ per loop `dir`, `name`, `view`, `foot_why`,
`candidates` (the two strikes: `strike` 0 and 1, `frame` in `cycle/`, `path` to that frame; the
first is the frame the loop now starts on, the second half a cycle on) and `settle` (the two
`--foot` arguments). Whoever looks — a person, the agent, or a vision call shown the two frames —
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index b7ad6e3..1fee041 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -354,9 +354,10 @@ apart. A frame that falls between two source frames is made by RIFE, and the com
is needed and RIFE is not installed; `--between nearest` makes none. A frame RIFE made that melted
(lost its outline where legs crossed too far) is replaced by the nearer source frame and named
(`--between auto`, the default; [loop repair](loop-repair.md) section 4). A loop whose view cannot
-tell its feet apart starts on its larger strike and is listed under the report's `unnamed_feet` with
-its two strike frames in `cycle/`: look at the first, say which own foot lands there, and run the same
-alignment again with `--foot <loop>=left|right` — that loop alone turns to start on the set's foot
+tell its feet apart — or tells them apart by too small a margin (`foot_why` `low-margin`) — starts
+on its larger strike and is listed under the report's `unnamed_feet` with its two strike frames in
+`cycle/`: look at the first, say which own foot lands there, and run the same alignment again with
+`--foot <loop>=left|right` — that loop alone turns to start on the set's foot
(`start_foot_source: "given"`).
`--character` or `--motion` words that turn the subject another way than `--facing`, or put a
diff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.py
index 28a9cea..07da8db 100644
--- a/sprite_gen/video/align.py
+++ b/sprite_gen/video/align.py
@@ -79,9 +79,14 @@ LOW_ALPHA, STRIDE_MIN, REACH_MIN, BODY_RUN = legs_mod.LOW_ALPHA, legs_mod.STRIDE
START_FOOT = "right" # every loop of a set starts as this own foot lands, where its view can tell
SHADE_BAND = 0.15 # the shade cue reads the feet and lower legs: the lowest 15 % of the body
# The two strikes must differ by this to name a foot (`strike_foot`): shade in luma (0..1), depth in
-# body heights. A smaller difference is the drawing, not the feet, and the foot is left unnamed.
-SHADE_MARGIN = 0.015
+# body heights. A smaller difference is the drawing as much as the feet, and the foot is left unnamed
+# (`low-margin`) for whoever looks (`unnamed_feet`): a foot named wrong turns the loop half a cycle off
+# with nobody asked, an unnamed one costs one look. The shade's margin is set above the margins at which
+# it has named a foot wrong on drawn walks and under those at which it named them right
+# (docs/loop-repair.md section 4).
+SHADE_MARGIN = 0.025
FOOT_MARGIN = 0.01
+LOW_MARGIN = "low-margin" # how `foot_why` starts where the two strikes differ by less than the margin
# A cue that does not swing with the step is the drawing's own flicker: its once-a-cycle swing (first
# harmonic) must be at least this share of its spread over the cycle.
CUE_RHYTHM = 0.25
@@ -272,7 +277,7 @@ def strike_foot(frames: list[Image.Image], strikes: tuple[int, int], view: str,
The cue must follow the step — its once-a-cycle swing at least CUE_RHYTHM of its spread over
the cycle — and, read over each strike frame and its two neighbours, the two strikes must differ
by FOOT_MARGIN (depth, of the body's height) or SHADE_MARGIN (luma); otherwise the foot is not
- named."""
+ named, `why` starting LOW_MARGIN."""
n = len(frames)
lateral = view in handed_mod.LATERAL_VIEWS
cue = (lambda f: _shade_cue(f, facing)) if lateral else _depth_cue # type: ignore[arg-type]
@@ -286,8 +291,10 @@ def strike_foot(frames: list[Image.Image], strikes: tuple[int, int], view: str,
"margin": round(margin, 4), "rhythm": round(rhythm, 3)}
if rhythm < CUE_RHYTHM:
return {**record, "feet": None, "why": f"the {record['cue']} does not follow the step (rhythm {rhythm:.2f})"}
- if margin < (SHADE_MARGIN if lateral else FOOT_MARGIN):
- return {**record, "feet": None, "why": f"the two strikes look alike in {record['cue']} ({margin:.4f})"}
+ least = SHADE_MARGIN if lateral else FOOT_MARGIN
+ if margin < least:
+ return {**record, "feet": None, "why": f"{LOW_MARGIN}: the two strikes differ by {margin:.4f} in {record['cue']}, "
+ f"under the {least:g} it takes to name a foot"}
hi = 0 if values[0] > values[1] else 1
at = {s: handed_mod.placement(s, view, facing) for s in handed_mod.SIDES}
if lateral:
diff --git a/tests/video/test_cycle_align.py b/tests/video/test_cycle_align.py
index b0494e4..e193512 100644
--- a/tests/video/test_cycle_align.py
+++ b/tests/video/test_cycle_align.py
@@ -72,14 +72,14 @@ def _old_top_line_start(frames: list[Image.Image]) -> int:
return max(range(n), key=lambda k: tops[(k - 1) % n] + 2 * tops[k] + tops[(k + 1) % n])
-def _figure(phase: float, *, view: str, legs: bool = True, bob_px: int = 2, shaded: bool = True) -> Image.Image:
+def _figure(phase: float, *, view: str, legs: bool = True, bob_px: int = 2, shaded: bool = True, far_darker: int = 60) -> Image.Image:
"""A drawn walker at `phase` (radians): its own right heel lands at 0, its left at pi. The body
bobs lowest (by `bob_px`) a sixth of a step after a heel lands; two thin ears on top flop on their
own rhythm, lowest half a step after it, and further than the body bobs.
`side`: faces right, its feet swing apart along the ground; the right leg is the near one, drawn
- light over the far left leg, which is shaded (`shaded`). `front`: the feet stay side by side, its
- right foot on the picture's left, and the foot stepping toward the viewer is drawn lower. With no
+ light over the far left leg, which is shaded (`shaded`) `far_darker` levels darker. `front`: the
+ feet stay side by side, its right foot on the picture's left, and the foot stepping toward the viewer is drawn lower. With no
legs the body sits on the ground and squats as it bobs."""
a = np.zeros((H, W, 4), dtype=np.uint8)
bob = round(bob_px * (1 + math.cos(2 * phase - math.pi / 3)) / 2)
@@ -90,9 +90,8 @@ def _figure(phase: float, *, view: str, legs: bool = True, bob_px: int = 2, shad
a[top - 26 + flop:top, x:x + 4] = (240, 180, 190, 255) # an ear: a narrow run
if legs:
if view == "side":
- for sign, leg, foot in ((-1, 150, 50), (1, 210, 110)): # far left leg first, near right leg over it
- if not shaded:
- leg, foot = 210, 110
+ shade = far_darker if shaded else 0
+ for sign, leg, foot in ((-1, 210 - shade, 110 - shade), (1, 210, 110)): # far left leg first, near right leg over it
fx = 50 + round(sign * 18 * math.cos(phase))
a[top + 58:106, fx - 3:fx + 3] = (leg, leg, leg, 255)
a[100:106, fx - 7:fx + 7] = (foot, foot, foot, 255)
diff --git a/tests/video/test_cycle_align_foot_margin.py b/tests/video/test_cycle_align_foot_margin.py
new file mode 100644
index 0000000..2516ca4
--- /dev/null
+++ b/tests/video/test_cycle_align_foot_margin.py
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: Apache-2.0
+"""A foot the view's cue names by a small margin is not named (docs/loop-repair.md section 4): the
+loop is listed under `unnamed_feet` with `foot_why` starting `low-margin`, so whoever looks — a
+person or a vision call — names it with `--foot`, and a cue that clears the margin names it as before.
+
+The figures are the drawn walker of test_cycle_align seen from the side, its far leg drawn
+`far_darker` levels darker than the near one: 3 levels part the two strikes by 0.0235 in luma (under
+the margin), 4 levels by 0.0314 (over it), the default 60 by far more."""
+
+from __future__ import annotations
+
+import math
+
+from sprite_gen.video import align
+
+from tests.video.test_cycle_align import _cycle
+from tests.video.test_cycle_align_foot import _cut, _rows
+
+FAINT, CLEAR = 3, 4 # levels darker the far leg is drawn: a margin under SHADE_MARGIN, and just over it
+
+
+def test_a_shade_that_parts_the_strikes_by_less_than_the_margin_names_no_foot():
+ found = align.strike_foot(_cycle(view="side", far_darker=FAINT), (0, 6), "side", "right")
+ assert found["cue"] == "shade" and found["rhythm"] >= align.CUE_RHYTHM # it follows the step
+ assert 0.015 < found["margin"] < align.SHADE_MARGIN # named before (0.015); not now
+ assert found["feet"] is None and found["why"].startswith("low-margin: ")
+ assert f"{found['margin']:.4f}" in found["why"] and f"{align.SHADE_MARGIN:g}" in found["why"]
+
+
+def test_a_shade_that_clears_the_margin_names_the_foot_as_before():
+ shaded = align.strike_foot(_cycle(view="side"), (0, 6), "side", "right")
+ clear = align.strike_foot(_cycle(view="side", far_darker=CLEAR), (0, 6), "side", "right")
+ assert clear["margin"] >= align.SHADE_MARGIN
+ # its right heel lands at phase 0: the near (right) leg is in front, drawn light
+ assert clear["feet"] == shaded["feet"] == ["right", "left"]
+
+
+def test_a_low_margin_loop_is_listed_for_whoever_looks_and_the_others_stay_named(tmp_path):
+ dirs = [_cut(tmp_path, "S", view="front"), _cut(tmp_path, "E", view="side"),
+ _cut(tmp_path, "L", view="side", far_darker=FAINT), _cut(tmp_path, "C", view="side", far_darker=CLEAR)]
+ views = ["front", "side@right", "side@right", "side@right"]
+ report = align.align_set(dirs, views=views)
+ rows = _rows(report)
+ assert [rows[k]["start_foot_source"] for k in "SECL"] == ["engine", "engine", "engine", None]
+ assert [rows[k]["start_foot"] for k in "SEC"] == ["right"] * 3
+ low = rows["L"]
+ assert low["foot_why"].startswith("low-margin: ") and low["foot"]["margin"] < align.SHADE_MARGIN
+ [entry] = report["unnamed_feet"]
+ assert entry["dir"] == str(dirs[2]) and entry["foot_why"] == low["foot_why"]
+ assert [(c["strike"], c["frame"]) for c in entry["candidates"]] == [(0, 0), (1, 6)]
+ assert any(w.startswith(f"{dirs[2]}: starts on its larger strike, foot not named — low-margin: ") for w in report["warnings"])
+ # the answer comes back as for any unnamed loop, and the reason it was unnamed is kept
+ told = _rows(align.align_set(dirs, views=views, feet={"L": "right"}))["L"]
+ assert told["start_foot_source"] == "given" and told["foot_unnamed_why"].startswith("low-margin: ")
+
+
+def test_the_figure_shades_its_far_leg_by_the_levels_asked():
+ """The fixture itself: the margins the tests above rest on."""
+ margins = {d: align.strike_foot(_cycle(view="side", far_darker=d), (0, 6), "side", "right")["margin"] for d in (FAINT, CLEAR)}
+ assert math.isclose(margins[FAINT], 0.0235, abs_tol=0.0005) and math.isclose(margins[CLEAR], 0.0314, abs_tol=0.0005)