<feed xmlns='http://www.w3.org/2005/Atom'>
<title>sketchbook.git/examples/live/build.zig, branch main</title>
<subtitle>A small Zig platform for sketching games and toys</subtitle>
<id>https://git.0x4200.cafe/sketchbook.git/atom?h=main</id>
<link rel='self' href='https://git.0x4200.cafe/sketchbook.git/atom?h=main'/>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/'/>
<updated>2026-11-17T15:15:01Z</updated>
<entry>
<title>examples/live: the storyboard as a script, two minutes typed through the editor</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T11:04:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=3571b3e8bfb54d6f98ad3bc1f89147275716e5fc'/>
<id>urn:sha1:3571b3e8bfb54d6f98ad3bc1f89147275716e5fc</id>
<content type='text'>
test/story.script plays the survey's storyboard (reports/demo1.md, the
screen and the storyboard) through the editor and asserts State at each
beat: a tone typed (`out` 8 instructions, heard on the stream); 220
dragged with the pointer to 330 (245 on the way); a gradient (`color`
10, ending in hsv); `beat`, `kick` and `thump` opened above, `out =
thump`, the colour's brightness times `0.5 + kick` (both tapes now hold
the kick's exp: the picture pulses because it says kick); the last `)`
deleted (the problem at its byte, 162, the tape unchanged) and typed
back; inside thump's `sin(...)` (`f*`, `;`, `mi(`), Alt-o hears and sees
the call alone (17 instructions ending in sin) and Alt-i its argument
(16), Escape the program again; `root` with `seq`, `bass`, `out = bass +
thump`, `r` and the ring (`out` 35, `color` 31). Then the session played
back, paused, sought to the tone and the kick (each the live moment,
leaf by leaf), stepped back 30 frames (0.9 s, the gradient), live again
at the kick with the beat made a third faster (`f2`, `;`, `r3`), and the
first session sought to its end as it was: nothing overwritten. Each
beat's screenshot lands in .zig-cache/story/, named by it; the test step
plays it with test/live.script. The storyboard's programs use the
square units (`x / 4`, `y / 2 + 0.5` for a gradient over the window).

zig build test: 86 of 86 steps.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: the language's grammar, its colours and a new line's indent</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T10:51:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=f37732448a2a374281c9610d05a10315e97dcbbf'/>
<id>urn:sha1:f37732448a2a374281c9610d05a10315e97dcbbf</id>
<content type='text'>
grammar/grammar.js is the language as src/Lang.zig parses it, for
tree-sitter (24 lines): lines of `name = expression` parted by newlines,
`+ -` below `* /` below unary `-`, calls, parentheses, numbers (Lang's
digits, point and `e`), names, `#` comments as extras. `tree-sitter
generate` (tree-sitter 0.26.9; ABI 14, the CLI's without a
tree-sitter.json) wrote grammar/src/parser.c (918 lines) and its
tree_sitter/ headers, committed: the build compiles them into the sketch
as a static library and never runs the generator.

The `Language` is handed to the editor at run time (`tree_sitter_live`,
queries/highlights.scm and queries/indents.scm embedded). The parse is a
module's `Syntax`, kept between calls so Alt-i goes back the way Alt-o
came, handed to every key, forgotten at a jump (in `draw`, `in.jumped`)
and started again by a reload (the tree a reload leaves is leaked:
marked ponytail). `code` colours each run of bytes by `Syntax.colors` in
pardes's own theme (orchard, the first): a defined name as a keyword, a
called builtin as a string, numbers and comments as theirs, the rest in
the theme's ink.

indents.scm gives a new line no indent outside an open call or
parenthesis: pardes's plain indent is a level more after `)`, so every
line of this language that ends in a call pushed the next one in. The
library now reads a handed-in language's indent query (pardes, its own
change).

Test: test/grammar.zig parses with the grammar and compiles with Lang.zig
22 texts: the survey's program and two others both take; eleven broken
lines both refuse (an unclosed or extra parenthesis, a missing operand or
`=`, two numbers, `1.2.3`, a stray `$`); eight both parse but only
Lang.zig refuses, as only it knows names, builtins, arities and where a
colour may stand (a name used before it is defined or defined twice, a
builtin redefined or called with too few arguments, an unknown call, a
colour outside the color line, a name called). Lang.zig's survey is
public for it. zig build test: 85 of 85 steps.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: pardes's editor in State, typed with helix's keys</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T10:42:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=ed185f305731309cbddb981166678a552f2fda84'/>
<id>urn:sha1:ed185f305731309cbddb981166678a552f2fda84</id>
<content type='text'>
The plain buffer of part 1 gives way to pardes's text pane as a library
(`pardes-editor`, src/lib_editor.zig there): `Editor(.{ .text = 4096,
.undo = 16 KiB, .registers = 1024, .selections = 64 })`, a value of plain
data, 39,264 bytes of a State of 43,480. The package takes pardes by path
(`../../../02-pardes-code`, the checkout beside sketchbook's) with
`.editor = true` and its smallest tree-sitter set; sketchbook is spelled
`../../../sketchbook` as pardes spells it, since a package is told by its
path's spelling and sketchbook's build.zig cannot be two modules.

`update` turns events into keys: printables from `text` events only,
specials (Escape, Return, Backspace, Tab, arrows, Home, End, pages,
Delete) and ctrl or alt chords (helix's `A-I` an upper-case letter) from
`key_down`, a chord's letter dropped if it also comes as text. Each call
into the editor thaws the value into a static 128 KiB buffer reset for
the call (`update` may not allocate from the host; a key at 4 KiB of text
took 29 KiB of it). The text is compiled when the editor's `revision`
moves.

Measured (a scratch bench through `update`, the survey's program, 646
bytes, a key typed into its middle, 400 times): a typed key, edit and
compile, 59.5 us best and 78.8 mean in Debug, 7.4 and 7.8 in
ReleaseFast; a motion 6.4 and 0.3. The package's cold `zig build lib`
went from 3.1 s to 6.6 s, its first build under `--watch -fincremental`
from 4.0 to 5.9 s, and an edit of main.zig rebuilt under it from
0.062-0.067 s to 0.067-0.092 s.

Test: test/live.script types through helix now (`i`, the text, Escape,
`gl`, `h`, `rx` for the edit, `l` `d` to break the line, `u` to mend it)
and still replays to equal text, tapes and screenshots, its seeks moved
to the marks' new times. zig build test: 81 of 81 steps, 6 of 6 tests.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: the sound, the out tape on the GPU per sample</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T09:05:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=a4d1e3131499c17bd6f73e65154aa0c2b31c62b3'/>
<id>urn:sha1:a4d1e3131499c17bd6f73e65154aa0c2b31c62b3</id>
<content type='text'>
`pub const audio_pull = 256`; each frame `draw` runs synth.comp over as
many samples as keep the host's lead queued (`in.lead -| queued`, 8192
at most) and streams the block with f.audioBuffer, as spheres does. Time
is a sample clock in Session: set from State's time at every jump (a
seek, a step, a replay's start; the queue is dropped then, so the jump is
heard at once), and free-running otherwise, so a paused replay keeps
sounding its moment. When the out tape differs from the one the last
block played, the block crosses from the old tape to the new over its
length (`set crossfade false` turns that off, to hear what it saves).
The blocks are read back for the scope (an oscilloscope and a spectrum
along the bottom) and, after the console's `capture`, appended to the
sketch's capture.f32 beside its save. The status line shows the lead.

The tapes reach synth.comp in a storage buffer, uploaded per block: two
tapes are 4 KiB, and SDL_GPU's Vulkan backend binds a uniform block 4
KiB at a time (MAX_UBO_SECTION_SIZE), so a 4128-byte Synth block read its
count as 0 past the cut and the kernel wrote nothing, silently: the
probe's first synth numbers timed that. Measured again (RTX 3050, Debug
host, two runs): every synth dispatch 0.08-0.14 ms, 60 or 128
instructions, 256 or 1024 samples, fading or not, the empty pass's cost
alone; the 4 KiB upload 0.07-0.08.

Measured on SDL's dummy driver (nothing audible) from captures:
out = 0.3 * sin(t * tau * 220): peak 0.3000, RMS 0.2121, fundamental
220.000 Hz; edited to 330 in one keystroke, 330.000 Hz. The largest
sample-to-sample step across the edit: 0.0131 with the crossfade (a
330 Hz sine's own steepest step is 0.0130), 0.3725 without; into the
first sound, 0.0011 and 0.2967. The survey's program: peak 0.50, RMS
0.16, its bass at 55.0 Hz.

Test: live.script also expects the stream to receive the GPU's blocks,
and compares screenshots above the scope. zig build test: 68 of 68 steps.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: the picture, typed over itself</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T09:03:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=c300a059850115a87a34456dfd60ac97c4a09890'/>
<id>urn:sha1:c300a059850115a87a34456dfd60ac97c4a09890</id>
<content type='text'>
The sketch: State holds the text (a plain 4 KiB buffer, typed characters
appended, backspace deleting the last, return a newline: marked ponytail,
the place pardes's editor takes in part 2), the last good out and color
tapes, the problem and the time, summed from recorded ticks. `update`
compiles the text at every keystroke; a program that parses replaces the
tapes and clears the problem, one that does not sets the problem and
changes nothing else, so the last good picture stays.

`draw` runs picture.frag over the color tape into an image the size of
the canvas, 1280x720, or half of it when the tape is longer than 64
instructions (the probe: 128 took 2.7 ms at full size, 0.85 at half),
and scales it up. The text is drawn over it on a dark band with the
library's text calls (the code face at 1.25, a column a fixed advance),
the caret at the end, the problem as a red mark under its byte and its
words under the text, and live/recording/replay/paused with the time in
a corner.

Test: test/live.script, the start of the scripted proof: a tone typed
(its eight instructions asserted), a gradient (hsv over x and y, four),
an edit (y to x: three, the picture different), a broken line (the
problem at byte 52, the tape and the picture the same) and its mend.
zig build test: 56 of 56 steps, 6 of 6 tests.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: the language, text in, a tape and a problem out</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T09:00:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=e7679f416daeee551e81a592c7fe06b8d8f7b705'/>
<id>urn:sha1:e7679f416daeee551e81a592c7fe06b8d8f7b705</id>
<content type='text'>
Lang.compile reads lines of `name = expression` over t, x and y (+ - * /,
unary minus, parentheses, numbers, # comments) and returns either a
Program, the out and color tapes, or a Problem: a byte of the text and
words. The builtins are one table, `builtins` (call, op, arity, value,
doc): the survey's sin, cos, exp, log, pow, sqrt, abs, floor, fract, min,
max, clamp, mix, step, smoothstep, atan2, noise, saw, sqr, tri, seq, hsv,
rgb, tau and pi, and the inputs t, x, y. A name is defined once, before it
is used; builtins cannot be renamed; hsv and rgb are colours, so only the
whole color line can be one.

Each tape is emitted from its line's root, depth first, each term once, so
it holds only what the line reaches; t, x and y are a term each however
often named, and a negative number is a number. seq's values go in
registers side by side: as emitted when they are fresh numbers, else
copied. noise's missing arguments are 0.

Nothing is allocated: the compiler is a struct on the stack, 512 terms,
128 names, 32 levels of nesting, 17 arguments (seq's 16 values), 128
instructions a tape, about 28 KiB in all; past any of them is a problem
in words ("the out line needs more than 128 instructions", at the line).

vm.glsl's smoothstep is written out: GLSL leaves lo &gt; hi undefined, and
the survey's ring is smoothstep(0.03, 0, ...).

Tests: a tone instruction by instruction; the survey's 20-line program
(out 54 instructions, color 46, neither holding the other's terms, every
operand an earlier register); every builtin; precedence, comments and
numbers; 24 problems, each with its byte and words; each capacity, met
and passed. zig build test: 6 of 6.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
<entry>
<title>examples/live: the interpreter of a tape, and its probe</title>
<updated>2026-11-17T15:15:01Z</updated>
<author>
<name>Gabriel Schneider</name>
<email>gbrls@0x4200.cafe</email>
</author>
<published>2026-11-17T08:50:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x4200.cafe/sketchbook.git/commit/?id=1637cf5efa338fee7797ba83f264dcab5bde4800'/>
<id>urn:sha1:1637cf5efa338fee7797ba83f264dcab5bde4800</id>
<content type='text'>
Demo 1's route: a program becomes a flat tape of at most 128 instructions
(src/Lang.zig: the ops, the instruction, the tape and the two uniform
blocks that carry it; build.zig writes Lang.Op out as ops.glsl, so the op
numbers have one definition), and ONE interpreter, shaders/vm.glsl, runs it
per pixel (picture.frag) and per sample (synth.comp, crossing from the
tape it replaces over the first `fade` samples). Instruction i writes
register i; the tape is pushed as uniforms.

The probe measures it before anything else is built: `zig build probe`
plays made-up tapes (every instruction reaching the last, a noise in ten)
under --profile-gpu. RTX 3050 (driver 620.70.06), Debug host, means of 601
frames, three runs agreeing within 0.07 ms:

  picture, empty tape   720p 0.14-0.23    1080p 0.19-0.28 (a pass's cost)
  picture, 60           720p 1.38-1.45    1080p 2.89-2.96
  picture, 128          720p 2.71-2.81    1080p 5.86-5.95
  picture, 128 at 640x360       0.85-0.94

The budget, under 2 ms at 1280x720: 60 instructions meet it, 128 do not.
The cheap fixes, on 128 at 720p: the tape in a storage buffer 2.97-3.03
(worse); the registers as an array of 16 (kept in registers, indexing
turned into selects) 5.82-5.93 (twice as slow); the 128-array with only
16 slots used 2.11-2.34 (cache footprint: a register allocator would buy
about a sixth); half resolution 0.85-0.94. So the sketch will draw a
tape longer than 64 instructions at half resolution, scaled up. The
variants are kept outside the tree. The synth's numbers taken here were
of a kernel that wrote nothing (its uniform block was past SDL's 4 KiB):
the sound's change measures it again.

Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
</content>
</entry>
</feed>
