Disabled capsules/artemis/init.4th block 4170's ART-STRESS-CAMPAIGN -- its own comment already said to revert to disabled once the K-invariant/ heartbeat verification run (item 4.6, closed earlier this session) was done. This was the actual ~25-30 minute wall blocking interactive REPL access, unrelated to any DoE mechanism. Verified capsules/turtle.4th and capsules/sdk.4th live in a gtk-display QEMU session: a red hexagon (6 100 POLYGON) and a green self-intersecting star (100 STAR) both render with correct geometry and color. Screenshot in evidence/amd64/. Two real obstacles found and worked around along the way: CS's full- framebuffer PLOT loop is far slower under TCG than previously documented (closer to 20+ minutes than "slow"), and the kernel's heartbeat CSV logging draws to the same console surface PLOT writes pixels to, overwriting drawings within a fraction of a second unless silenced first with the existing HB-OFF word. Both HOWTOs updated to record this. Re-verified full three-arch acceptance boot (POST, DoE, parity) with the ART-STRESS-CAMPAIGN change: 1012/0/0 and matching dict_hash on all three, identical to the pre-change baseline. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
8.3 KiB
Turtle Graphics HOWTO — capsules/turtle.4th
Status: WORKING. First entry in the "cookbook" track Captain Bob asked
for on 2026-08-18 (memory: project-stadium-logo-turtle-idea, floated
2026-08-11) — a small, low-stakes demo capsule meant to make the CANVAS/
framebuffer substrate satisfying to drive interactively, not a production
subsystem. Second cookbook entry (DoE package/library HOWTO) is a separate,
later doc.
What this is
A limited LOGO-style turtle graphics vocabulary: a cursor with a position
and heading that moves around the screen, drawing a trail when its "pen" is
down. Classic commands — FORWARD, BACK, LEFT, RIGHT, PENUP/
PENDOWN — composed entirely in FORTH on top of primitives that already
exist:
PLOT/FB-WIDTH/FB-HEIGHT(src/word_source/framebuffer_words.c) — raw hardware-boundary pixel write, kernel-only (no-op on hosted builds).LINE/CIRC-PT/Q.SIN/Q.COS(capsules/fabric.4th,src/word_source/q48_words.c) — Cartesian line-drawing (Bresenham, in raster space) and Q48.16 fixed-point trig, both already load-bearing for the glyph-rendering pipeline.
No new C words were added for this — per this repo's standing rule ("compose in FORTH first; new C primitives are justified only for raw hardware access, atomics, syscalls, or freestanding kernel ops"), a turtle is pure policy on top of primitives that already exist.
Prerequisites
capsules/fabric.4thmust be loaded first — the turtle uses itsLINEword directly, and (transitively)Q.SIN/Q.COS/Q.FROM-INT/Q.TO-INT/Q.*/Q.+fromq48_words.c, which is always registered.- A real framebuffer.
PLOTis a no-op on hosted (make) builds, so the turtle is only visually meaningful under the kernel/QEMU build with thegtkdisplay (make -f Makefile.starkernel ARCH=<arch> qemu). It loads and runs its arithmetic identically on hosted builds — useful for logic verification, not for seeing anything.
Loading it
Not wired into init.4th — it is not part of the Mama VM's boot sequence,
by design (memory: "invoked from the REPL", not autoloaded). Load and run it
interactively:
S" turtle.4th" EXEC
TURTLE-DEMO
TURTLE-DEMO clears the screen, draws a cyan hexagon, then a magenta
five-pointed star from the same starting point — a one-call visual smoke
test.
Vocabulary
| Word | Stack effect | Effect |
|---|---|---|
HOME |
( -- ) |
Turtle to screen center, heading east (0°), pen down, color white. Does not clear the screen. |
CS |
( -- ) |
Clear the framebuffer to black. Plain nested PLOT loop (no fill primitive exists) — slow under TCG for a full screen; a one-shot clear, not a per-frame op. |
PENUP / PENDOWN |
( -- ) |
Whether FORWARD/BACK draw while moving. |
SETCOLOR |
( color -- ) |
24-bit 0xRRGGBB, same format PLOT takes directly. |
SETXY |
( x y -- ) |
Jump to (x y) without drawing, regardless of pen state. |
SETHEADING |
( deg -- ) |
Absolute heading in degrees, 0 = east, counterclockwise positive. |
FORWARD |
( n -- ) |
Move n pixels along the current heading, drawing a LINE from old to new position if the pen is down. |
BACK |
( n -- ) |
FORWARD in reverse (NEGATE FORWARD). |
LEFT |
( deg -- ) |
Turn deg degrees counterclockwise in place. |
RIGHT |
( deg -- ) |
Turn deg degrees clockwise in place (NEGATE LEFT). |
POLYGON |
( sides len -- ) |
Regular polygon, drawn from the turtle's current position/heading — call HOME first for a clean start. |
STAR |
( len -- ) |
Classic self-intersecting 5-pointed star (FORWARD + a 144° turn, five times — not 360/5=72°, which draws a plain pentagon). |
TURTLE-DEMO |
( -- ) |
CS, a cyan hexagon, then a magenta star. |
Internal state (TX/TY/THEAD/TPEN/TCOLOR and the FORWARD scratch
pair TNX/TNY) is exposed as ordinary VARIABLEs, matching every other
piece of drawing-fabric state in fabric.4th — nothing here is hidden or
C-side.
Worked example — a five-pointed star by hand
S" turtle.4th" EXEC
HOME
16711935 SETCOLOR ( magenta, 0xFF00FF )
100 STAR
Equivalent to running TURTLE-DEMO's second half. STAR is not built from
POLYGON with a different turn angle — a mathematically regular pentagon
(5 100 POLYGON, turning 360/5 = 72° per corner) is convex and does not
self-intersect; the classic five-pointed star shape requires overshooting
the turn to 144° per corner instead, which is why STAR is its own word
rather than a POLYGON call with n=5.
Design notes for anyone extending this
- Heading storage.
THEADstores heading directly in Q48.16 radians (not degrees) soFORWARDcan hand it straight toQ.SIN/Q.COSwithout a conversion on every step.LEFT/RIGHT/SETHEADINGdo the degrees→radians conversion once, at the turn, via theDEG2RADconstant (1144, Q48.16 forπ/180 ≈ 0.0174533). - No manual angle wraparound.
q48_sin_approx/q48_cos_approx(src/math_portable.c) range-reduce internally viaq48_reduce_angle(), soTHEADcan accumulate indefinitely across many turns without the turtle needing to keep it inside[0, 2π)itself. - Coordinates are Cartesian, not raster.
TX/TYfollowfabric.4th's own convention (Y increases upward) — the Y-flip to raster space happens once, insideLINE's call toTO-RASTER/CART-Y. The turtle never touches raster coordinates directly. - z is always 0.
fabric.4th'sLINEtakes 3D Cartesian points (x1 y1 z1 x2 y2 z2 color) because it also serves the cavalier-projection glyph/cube-drawing code; the turtle is flat, so it always passes0for both z arguments.
Verification performed
mkcapsule --lint capsules/— clean, no block-size or namespace violations (block range5100–5108, clear offabric.4th's highest block at5002).- Logic verified on the hosted build:
fabric.4th's core blocks (4900–4909) plusturtle.4thpiped directly into./build/amd64/standard/ starforth, exercisingHOME,SETCOLOR,POLYGON,STAR,FORWARD, and (transitively)LINE— zero VM errors, correct stack balance throughout (--log-debugtrace confirms everyFORWARDcall computesdx/dyviaQ.COS/Q.SINcorrectly and callsLINEwith the expected seven arguments). - Baked cleanly into
capsule_generated.c(capsule[35]) on a fullMakefile.starkernel ARCH=amd64build, zero warnings; boot verified clean through POST and into the DoE campaign with the capsule present (not autoloaded, so it cannot affect the boot path it isn't on). - Visually confirmed 2026-08-19, live in a
gtk-display QEMU session: a red6 100 POLYGON(hexagon) and a green100 STARboth render with correct geometry and color. Screenshot:evidence/amd64/qemu-screenshot-20260819-074637-turtle-polygon-star- verified.png. Two things had to be worked out first, worth recording since they'll matter for any future interactive session:- The
~25–30minute wall this doc used to describe turned out to actually becapsules/artemis/init.4th'sART-STRESS-CAMPAIGN(auto-runs at Artemis's birth, unrelated to any DoE mechanism documented inDOE-LIBRARY-HOWTO-20260819.md) — it carried a staleTEMP: ... revert once that run is donecomment for a verification run that had already closed. Reverted to disabled, matching the file's own note (FABRIC-2.md section K/L). - The kernel's heartbeat CSV logging (
[HADES][DOE ]rows) draws to the same console surfacePLOTdraws pixels to, and scrolls continuously — anything drawn gets visually overwritten within a fraction of a second unless silenced first withHB-OFF(registered insrc/starkernel/doe_log.c;HB-ONre-enables it). Do this before drawing anything you want to actually see. TURTLE-DEMO's ownCScall turned out to be dramatically slower than "slow under TCG" suggested — closer to 20+ minutes than a minor delay, for a full-framebuffer nestedPLOTloop. For a quick visual check, callHOME/SETCOLOR/POLYGON/STARdirectly and skipCS.
- The