Port the parametric DSL into the editor - #8
Merged
Merged
Conversation
15 primitives, each with a declared period, composed with set/union/intersect/
xor/subtract and sized to a common multiple of every layer's period so the result
tiles seamlessly by construction. tools/dsl_prototype.py has been the reference
implementation since before the editor existed and tools/dsl_demo.py has proved
28 programs tile exactly on every commit; none of it had ever reached a user.
A Program panel makes it usable by hand: five presets, the program as editable
JSON, live size and ink readout, and a Replace canvas that renders into a
two-colour document. Bad input reports and does not crash — an unknown shape type
says so, malformed JSON says where.
Four things in the Python do not survive a literal translation, and each is a
silent wrong answer rather than an error. They are named at the top of the ported
block:
round() banker's rounding, so round(2.5) is 2 where Math.round gives 3. It
decides wave offsets and canvas sizing.
% a floor modulo in Python, a remainder in JS. Every expression that
can go negative routes through floorMod.
// floors, where |0 truncates toward zero.
_hash2 multiplies by constants near 2^31, which passes 2^53 and silently
drops low bits, so the mixing steps use Math.imul.
tests/fixtures/dsl.json is the oracle: 62 programs — the 28 from the gallery,
every primitive again at non-default parameters, every composition op over the
same two shapes, and every post transform on an asymmetric source — compared as
encoded patternData, because a one-pixel difference still changes the string.
59 of the 62 passed on the first run. The three failures were all `text`, and the
cause was that the glyph tables had been typed in by hand rather than taken from
the emitted file: one wrong row in the 5x7 'D' and half of 3x5 rewritten. They
are now emitted from the source tables, and the fixture carries those tables so a
future slip is reported as "5x7 font: 1/36 glyphs differ (D)" rather than as a
lit-pixel count being off by sixteen.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCrKKTD2mwHx8Fm1EnJiQ3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 4 of the v0.2.0 plan — generation.
15 primitives, each with a declared period, composed with set/union/intersect/xor/subtract and sized to a common multiple of every layer's period, so the result tiles seamlessly by construction rather than by luck.
tools/dsl_prototype.pyhas been the reference implementation since before the editor existed, andtools/dsl_demo.pyhas proved 28 programs tile exactly on every commit. None of it had ever reached a user.The panel
Five presets, the program as editable JSON, a live size and ink readout, and a Replace canvas that renders into a two-colour document keeping any duotone already chosen. Bad input reports rather than crashing — an unknown shape type says so, malformed JSON says where. Driven in the real app to confirm all four paths.
Four things that don't survive a literal translation
Each is a silent wrong answer, not an error, so each is named at the top of the ported block:
round()round(2.5)is 2 whereMath.roundgives 3. Decides wave offsets and canvas sizing.%floorMod.//|0truncates toward zero._hash2*drops low bits. UsesMath.imul.The oracle
tests/fixtures/dsl.json— 62 programs: the 28 from the gallery, every primitive again at non-default parameters (a port that ignores an argument still passes on defaults), every composition op over the same two shapes, and every post transform on an asymmetric source. Compared as encoded patternData, since a one-pixel difference still changes the string.What the fixture caught
59 of 62 passed on the first run. All three failures were
text, and the cause was mine: I typed the glyph tables by hand instead of using the file I had just emitted mechanically — one wrong row in the 5×7D, and half of 3×5 rewritten.They are now emitted from the source tables, and the fixture carries those tables so the next slip reports as:
rather than as "384 lit pixels, oracle says 400". I verified that check bites by corrupting a glyph.
Verification
./tools/verify-all.shgreen, now includingDSL oracleandeditor DSL vs oracle. Rendered Plaid in the running app: 32×30, sized to the LCM of periods 8 and 6, tiling seamlessly in the preview.🤖 Generated with Claude Code
https://claude.ai/code/session_01UCrKKTD2mwHx8Fm1EnJiQ3