Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): the order the feet are drawn in never reads a tail's tip dipping into the foot band as a foot: a frame either of whose sides is drawn over no column anything in the clip stands on is not read apart
Soohong Kimbd5c43de6dc3
diff --git a/sprite_gen/video/local_cycle.py b/sprite_gen/video/local_cycle.pyindex ce1e4f6..2cdd281 100644--- a/sprite_gen/video/local_cycle.py+++ b/sprite_gen/video/local_cycle.py@@ -111,7 +111,11 @@ SIDE_VIEW = 'side' # from the side the legs a step on are one silhouette, as ne# to p90, against the swing over the feet's distance apart, at ORDER_REACH of the body's height over them): a picture# rocking on its feet draws one foot lower and then the other. Then the changes' rate over the span, within# ORDER_SLACK of two, four or one, no two changes further apart than two of their mean, says two steps, four or one;-# from the side (SIDE_VIEW) it is not read.+# from the side (SIDE_VIEW) it is not read. Before all of it, a foot is drawn over the ground the walk stands on: a+# frame either of whose two sides is drawn over no column anything stands on the lowest row of in any frame of the clip+# (`ground`) is not read apart (`_off_ground`) — a tail's tip dipping into the foot band, read as a foot, would change+# the side drawn lower as no foot does; a foot lifted where none ever stands is left out with it. A tail hanging over+# the columns the feet stand on is still read as a foot: the gates above are what hold it.ORDER_ROWS = 2ORDER_TRAVEL = 0.8ORDER_SWAY = 0.5@@ -807,17 +811,28 @@ def _travel(order):return widest+def _off_ground(order):+ """The frames whose feet are read apart but either of whose two sides is drawn over no column anything stands on+ the lowest row of (`ground`) in any frame of the clip: a tail's tip dipping into the foot band, say."""+ ground = [part for o in order for part in o['ground']]+ return [k for k, o in enumerate(order)+ if o['apart'] and not all(any(_touch(o[side], part) for part in ground) for side in ('left', 'right'))]++def order_word(order, span):"""What the order the feet are drawn in (`order`, per frame: `legs.feet_order`) says of `span` frames — a crossinginterval (`read_cycles`) or a cut (`cut_word`): `says` `two steps`, `four steps` or `one step` where the clip showsits two sides of feet are two legs and the side drawn lower changes at that rate (ORDER_WORDS, within ORDER_SLACK),else None with why (module notes before ORDER_ROWS). Returns the record: `apart` (the share of frames whose feet are- seen apart), `swing` (the depth's p10 to p90, in rows), `floor`, and where read `changes` (frames between which the- lower side changes), `slides` (those whose contacts touch), `spacing` (the feet's median distance apart) and- `travel` (`_travel`), in px, `sway` and `tilt` (the sway a tilt would need), `per` (changes per span)."""+ seen apart, less `off_ground`: where any are, the frames read apart with a side drawn over no ground the clip stands+ on, `_off_ground`), `swing` (the depth's p10 to p90, in rows), `floor`, and where read `changes` (frames between+ which the lower side changes), `slides` (those whose contacts touch), `spacing` (the feet's median distance apart)+ and `travel` (`_travel`), in px, `sway` and `tilt` (the sway a tilt would need), `per` (changes per span)."""+ off = _off_ground(order)+ order = [{**o, 'apart': False} if k in off else o for k, o in enumerate(order)]seen = [o for o in order if o['apart']]apart = len(seen)/len(order) if order else 0.0- word = {'apart': round(apart, 3)}+ word = {'apart': round(apart, 3), **({'off_ground': off} if off else {})}if apart < legs_mod.FEET_APART_SHARE or len(seen) < 3:return {**word, 'says': None, 'why': f'the feet are seen apart in {apart:.0%} of the frames (from 'f'{legs_mod.FEET_APART_SHARE:.0%}): the order they are drawn in is not read'}diff --git a/tests/video/test_walk_steps.py b/tests/video/test_walk_steps.pyindex d75154b..935a353 100644--- a/tests/video/test_walk_steps.py+++ b/tests/video/test_walk_steps.py@@ -37,7 +37,11 @@ shows its two sides of feet are its legs — no foot planted on the ground slideupper body does not rock over them — so the crossings mark cycles and the cut stands on the same word; labelled theside view, the order is not read. A side walk lifting its swing foot draws one foot lower and then the other too, butits planted foot passes under the body: never read so, whatever its label; nor a picture rocked on its feet, nor feet-drawn level. Nor does the order stand a cut the search kept where none of the clip's two-step cuts closes.+drawn level. Nor does the order stand a cut the search kept where none of the clip's two-step cuts closes. A tail whose+tip dips into the foot band beside the feet is never read as a foot: drawn over no column anything stands on, the+frames whose one side it is are left out, and the order says what the walker drawn without it says — two steps a cycle+of the walker whose feet meet once a cycle, one step an interval of one whose feet meet once a step (never cut one step+unnamed), nothing of a side walk.A walk the search already cuts two steps long, joined at the walk's own point, is cut exactly as before; a bodywhose feet cannot be read is cut as before. Synthetic frames only."""@@ -158,7 +162,7 @@ def _outward(k: float, *, cycle: float, bob: int = 3, whole: bool = False, arm:return im-def _apart(k: float, *, cycle: float, rock: float = 0, slide: bool = False) -> Image.Image:+def _apart(k: float, *, cycle: float, rock: float = 0, slide: bool = False, each_step: bool = False) -> Image.Image:"""A walker seen from the front whose feet stay apart: the foot stepping toward the camera is drawn lower, up to 3 pxunder the ground and the other as far over it, so the foot drawn nearer changes sides once a step; the right foot,drawn higher, swings in to meet the left over it and back, so the feet meet on the screen once a cycle, briefly, and@@ -167,16 +171,18 @@ def _apart(k: float, *, cycle: float, rock: float = 0, slide: bool = False) -> I`rock`: its feet drawn level and still, the whole picture rocked that many degrees either way about its feet once acycle, one foot drawn lower and then the other with no step. `slide`: the right foot swings in to meet the left asboth stand level on the ground and back as it is drawn lower, planted, sliding along the ground as only a foot seen- from the side does."""+ from the side does. `each_step`: the left foot too swings in to meet the right while it is drawn higher, so the+ feet meet once a step."""ph = 2 * math.pi * k / cycleim = Image.new("RGBA", (300, 220))d = ImageDraw.Draw(im)x, y = 90, 40drop = 0 if rock else round(3 * math.sin(ph))inward = 0 if rock else 10 * max(0.0, -math.cos(ph)) ** 4 if slide else 10 * max(0.0, math.sin(ph)) ** 2+ outward = 10 * max(0.0, -math.sin(ph)) ** 2 if each_step else 0swing = ARMS_IN * math.sin(ph)d.rectangle((x + 14 - swing - 4, y + 34, x + 14 - swing + 4, y + 72), fill=(150, 150, 150, 255))- for lx, sole, t in ((x + 6, GROUND + drop, 0), (x + 22 - inward, GROUND - drop, 1)):+ for lx, sole, t in ((x + 6 + outward, GROUND + drop, 0), (x + 22 - inward, GROUND - drop, 1)):d.rectangle((lx - 5, y + 80, lx + 5, sole), fill=(60 + t, 60 + t, 70 + t, 255))d.rectangle((x, y + 30, x + 28, y + 84), fill=(200, 80, 80, 255))d.rectangle((x + 2, y, x + 26, y + 28), fill=(230, 200, 170, 255))@@ -184,6 +190,19 @@ def _apart(k: float, *, cycle: float, rock: float = 0, slide: bool = False) -> Ireturn im.rotate(rock * math.sin(ph), resample=Image.Resampling.NEAREST, center=(x + 14, GROUND)) if rock else im++def _dipping_tail(draw, *, hip: tuple[int, int], reach: int, beat: float = 17):+ """`draw` with a tail from `hip`, on the body, to a tip `reach` px left of it, rising and falling 8 px either way on+ a beat of its own (`beat` frames): the tip dips into the foot band a third of the time or so, never as low as the+ feet nor over a column they stand on."""+ def drawn(k: float) -> Image.Image:+ im = draw(k)+ tip = (hip[0] - reach, GROUND - 12 + round(8 * math.sin(2 * math.pi * k / beat)))+ ImageDraw.Draw(im).line((hip, tip), fill=(180, 120, 40, 255), width=6)+ return im+ return drawn++def _alike(k: float, *, cycle: float, phase: float = 0, tone: int = 1, lean: float = 0, leg_tone: int | None = None,leg_half: int = 5, lift: int = 0, light: tuple[str, int] | None = None, bob: int = 3, whole: bool = False,air: int = 0, slide: int = 0, limp: int = 0, top: str = "flat", arm: float = 16) -> Image.Image:@@ -573,6 +592,21 @@ def test_a_side_walk_whose_swing_foot_lifts_is_never_cut_on_the_order_its_feet_aassert report["cycle"]["cut_witness"].get("by") != ["order"]+def test_a_front_walk_whose_feet_meet_once_a_step_its_tail_dipping_into_the_foot_band_is_never_cut_one_step_unnamed(tmp_path):+ """Seen from the front, the feet apart, each swinging in to meet the other while it is drawn higher: the feet meet+ on the screen once a step, every 15 frames of a 30-frame cycle, and the foot drawn nearer changes sides once an+ interval. A tail's tip dips into the foot band beside the feet on a beat of its own. Labelled the front view, its+ crossings are never read as cycles, the order never stands a cut shorter than the cycle, and no cut under a cycle is+ handed out unnamed."""+ walker = _dipping_tail(lambda k: _apart(k, cycle=30, each_step=True), hip=(92, 100), reach=28)+ report = _cut(tmp_path / "out", _keyed(tmp_path, walker), "--view", "front")+ _not_silent(report, 30)+ c = report["cycle"]+ assert (c["step_count"].get("cycles") or {}).get("cycles") is not True+ assert c["cut_witness"].get("by") != ["order"] or abs(c["length"] - 30) <= 1.5, c["cut_witness"]++@pytest.mark.slow@pytest.mark.parametrize("tone, lean", [(1, 0), (4, 1)])def test_a_side_walk_whose_two_steps_look_alike_is_cut_two_steps_however_near_a_step_on(tmp_path, tone, lean):@@ -1540,6 +1574,38 @@ def test_the_order_the_feet_are_drawn_in_witnesses_nothing_where_the_clip_does_nassert word["says"] is None and why in word["why"], word[email protected]("each_step, span, says", [(False, 30, "two steps"), (False, 15, "one step"),+ (True, 15, "one step")])+def test_a_tail_whose_tip_dips_into_the_foot_band_is_never_read_as_a_foot(each_step, span, says):+ """The walker whose feet stay apart, a cycle 30 frames, its feet meeting once a cycle or once a step (`each_step`),+ with a tail whose tip dips into the foot band beside them: there the band's widest gap parts the tail from both+ feet, and the tail read as a foot puts the foot drawn lower on the side it is not, then back (the parent engine+ read it so, and the order said nothing of the walker whose feet meet once a cycle). The tail is drawn over no column+ anything stands on: the frames whose one side it is are not read apart (`off_ground`), no change is counted on+ them, and the order says what the walker drawn without it says — two steps in a cycle, one step in an interval of+ the walker whose feet meet once a step, never two."""+ walker = lambda k: _apart(k, cycle=30, each_step=each_step) # noqa: E731+ order = [legs.feet_order(_dipping_tail(walker, hip=(92, 100), reach=28)(k)) for k in range(FRAMES)]+ tail = [k for k, o in enumerate(order) if o["apart"] and o["left"][1] < 80]+ word = local_cycle.order_word(order, span)+ assert (word["says"] == "two steps") == (says == "two steps"), word+ assert tail and word["off_ground"] == tail and not {k for change in word["changes"] for k in change} & set(tail)+ plain = local_cycle.order_word([legs.feet_order(walker(k)) for k in range(FRAMES)], span)+ assert word["says"] == plain["says"] == says and "off_ground" not in plain, (word, plain)+++def test_a_side_walk_whose_tail_dips_into_the_foot_band_is_never_read_on_its_tail():+ """The side walk lifting its swing foot, its planted foot passing under the body, with a tail whose tip dips into+ the foot band behind it: the tail read as a foot moves the band's parting and the feet's distance apart with it+ (the parent engine said nothing of it all the same). Its frames are not read apart (`off_ground`), and the order+ says nothing on the planted foot passing under the body, as of the walk drawn without the tail."""+ walker = lambda k: _alike(k, cycle=46, phase=13, tone=4, lean=1, leg_tone=0, lift=6) # noqa: E731+ order = [legs.feet_order(_dipping_tail(walker, hip=(92, 90), reach=40)(k)) for k in range(FRAMES)]+ tail = [k for k, o in enumerate(order) if o["apart"] and o["left"][1] < 70]+ word = local_cycle.order_word(order, 23)+ assert tail and word["off_ground"] == tail and word["says"] is None and "under the body" in word["why"], word++@pytest.mark.parametrize("verdict", ["held_verdict", "step_verdict"])def test_a_cut_held_on_one_step_whose_record_names_no_line_is_refused_by_name(verdict):"""`held_verdict` (a public caller; `step_verdict` says it) names the line a cut held on one step rose and fell