summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 08:04:49 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit3571b3e8bfb54d6f98ad3bc1f89147275716e5fc (patch)
treef2bcff6ba76b3f4593cc72c89a7ce66d04a5afbd /examples
parentf0c4ef1a771f6b13cbd86cccdb56accfd39bbd69 (diff)
downloadsketchbook-3571b3e8bfb54d6f98ad3bc1f89147275716e5fc.tar.gz
sketchbook-3571b3e8bfb54d6f98ad3bc1f89147275716e5fc.zip
examples/live: the storyboard as a script, two minutes typed through the editor
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples')
-rw-r--r--examples/live/build.zig2
-rw-r--r--examples/live/test/story.script157
2 files changed, 158 insertions, 1 deletions
diff --git a/examples/live/build.zig b/examples/live/build.zig
index a07fe7d..cd686c0 100644
--- a/examples/live/build.zig
+++ b/examples/live/build.zig
@@ -49,7 +49,7 @@ pub fn build(b: *std.Build) void {
app.module.linkLibrary(grammar);
app.module.addAnonymousImport("highlights.scm", .{ .root_source_file = b.path("queries/highlights.scm") });
app.module.addAnonymousImport("indents.scm", .{ .root_source_file = b.path("queries/indents.scm") });
- const steps = app.addSteps(.{ .scripts = &.{b.path("test/live.script")}, .tests = &.{b.path("test/grammar.zig")} });
+ const steps = app.addSteps(.{ .scripts = &.{ b.path("test/live.script"), b.path("test/story.script") }, .tests = &.{b.path("test/grammar.zig")} });
const lang_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/Lang.zig"), .target = target, .optimize = optimize }) });
steps.test_step.dependOn(&b.addRunArtifact(lang_test).step);
diff --git a/examples/live/test/story.script b/examples/live/test/story.script
new file mode 100644
index 0000000..25e66f5
--- /dev/null
+++ b/examples/live/test/story.script
@@ -0,0 +1,157 @@
+# The storyboard (reports/demo1.md, section 4), two minutes typed through
+# the editor: a tone, its pitch dragged, a gradient, a kick shared by sound
+# and picture, a `)` deleted and put back, a probe, a bass line and a ring;
+# then the session played back, sought, stepped back and branched. State
+# is asserted at each beat; each beat's screenshot lands in
+# .zig-cache/story/, named by the beat.
+console capture
+frames 2
+# 0:05 a tone
+type i
+type out = sin(tau * 220 * t) * 0.3
+key escape
+expect problem.len 0
+expect out.len 8
+frames 30
+expect-audio 1
+console save tone
+screenshot .zig-cache/story/1-tone.png
+# 0:15 the pitch dragged, 220 to 330 (columns 16..18 of line 1; a step
+# every 4 pixels: 245 on the way)
+down 181 27
+move 281 27
+expect out.code[1].a 1131741184
+move 621 27
+up 621 27
+expect out.code[1].a 1134886912
+frames 10
+screenshot .zig-cache/story/2-drag.png
+# 0:25 a gradient behind the code
+type o
+type color = hsv(x / 4, 0.5, y / 2 + 0.5)
+key escape
+expect color.len 10
+expect color.code[9].op hsv
+frames 10
+screenshot .zig-cache/story/3-gradient.png
+# 0:35 a kick, shared: the picture pulses because it says kick too
+type gg
+type O
+type beat = t * 2
+key return
+type kick = exp(-7 * fract(beat))
+key return
+type thump = sin(tau * 48 * t * (1 + 2 * kick)) * kick * 0.5
+key escape
+type j
+type x
+type c
+type out = thump
+key return
+key escape
+type x
+type c
+type color = hsv(x / 4, 0.5, (y / 2 + 0.5) * (0.5 + kick))
+key escape
+expect problem.len 0
+expect out.len 20
+expect out.code[19].op mul
+expect color.len 20
+expect color.code[19].op hsv
+# the picture's tape has the kick's exp in it, as the sound's does
+expect color.code[16].op exp
+console save kick
+frames 20
+screenshot .zig-cache/story/4-kick.png
+# 0:55 a ) deleted: marked, and the last good program plays on
+type gl
+type d
+expect problem.at 162
+expect color.len 20
+frames 10
+screenshot .zig-cache/story/5-broken.png
+# 1:00 put back
+type a
+type )
+key escape
+expect problem.len 0
+frames 10
+screenshot .zig-cache/story/6-mended.png
+# 1:05 inside thump's sin, Alt-o: only the call is heard and seen; Alt-i
+# back inside it; Escape, the program again
+type gg
+type jj
+type f*
+type ;
+type mi(
+hold left_alt
+key o
+expect probe.len 17
+expect probe.code[16].op sin
+frames 10
+screenshot .zig-cache/story/7-probe.png
+key i
+expect probe.len 16
+expect probe.code[15].op mul
+release left_alt
+key escape
+expect probe.len 0
+# 1:15 a bass line under it, and the ring
+type o
+type root = seq(beat / 4, 55, 55, 65.4, 49)
+key return
+type bass = saw(root * t) * (1 - kick) * 0.25
+key escape
+type j
+type x
+type c
+type out = bass + thump
+key return
+key escape
+type O
+type r = sqrt(x * x + y * y)
+key escape
+type j
+type x
+type c
+type color = hsv(fract(beat / 16 + r), 0.6, smoothstep(0.06, 0, abs(r - 0.4 - 0.2 * kick)) + 0.2 * kick)
+key escape
+expect problem.len 0
+expect out.len 35
+expect out.code[34].op add
+expect color.len 31
+expect color.code[30].op hsv
+console save end
+frames 60
+screenshot .zig-cache/story/8-bass-ring.png
+# 1:40 played back, paused, sought to the tone and to the kick (each
+# moment's text, tapes and time as they were live, leaf by leaf), stepped
+# back half a second
+console play session 0
+frames 30
+console pause
+console seek 590
+expect-snapshot tone
+screenshot .zig-cache/story/9-sought-tone.png
+console seek 1405
+expect-snapshot kick
+console step -30
+expect time 0.9 ~0.001
+expect color.len 10
+screenshot .zig-cache/story/9-stepped-back.png
+# 1:55 live again at the kick, another way on: the beat a third faster
+console seek 1405
+console stop
+type gg
+type f2
+type ;
+type r3
+expect problem.len 0
+expect out.code[8].a 1077936128
+frames 30
+screenshot .zig-cache/story/10-branched.png
+# nothing was overwritten: the first session still ends as it did
+console play session 0
+frames 10
+console seek 2890
+expect-snapshot end