summaryrefslogtreecommitdiff
path: root/examples/noc/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
committerGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
commit6933f99ddb2d7103515d26838496309a807bba26 (patch)
tree991c2fe7d4a57957222876e190fa4d16a0fb889c /examples/noc/build.zig
parent82fca5c9f29124f37f6dcd08e73e6999ce44a69d (diff)
downloadsketchbook-6933f99ddb2d7103515d26838496309a807bba26.tar.gz
sketchbook-6933f99ddb2d7103515d26838496309a807bba26.zip
Move standalone sketches into sketchbook examples
Diffstat (limited to 'examples/noc/build.zig')
-rw-r--r--examples/noc/build.zig63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/noc/build.zig b/examples/noc/build.zig
new file mode 100644
index 0000000..cc13d24
--- /dev/null
+++ b/examples/noc/build.zig
@@ -0,0 +1,63 @@
+const std = @import("std");
+const sketchbook = @import("sketchbook");
+
+/// Nature of Code examples, one file each in src/. Every sketch has
+/// `test/<name>.script`; `timeline` adds `test/<name>.timeline.script`
+/// (record, then play, seek, step and replay to the same state; see
+/// accel_to_mouse's), and `reload` a hot-reload check: the sketch's library
+/// rebuilt with that edit, loaded mid-run by `test/<name>.reload.script`.
+const Sketch = struct {
+ name: []const u8,
+ timeline: bool = false,
+ reload: ?sketchbook.App.Edit = null,
+};
+
+const sketches = [_]Sketch{
+ // batch A
+ .{ .name = "random_walk", .timeline = true, .reload = .{ .file = "src/random_walk.zig", .old = ".w = 1, .h = 1 }, .black)", .new = ".w = 1, .h = 1 }, sk.Color.hex(0xff0000))" } },
+ .{ .name = "noise_walker", .timeline = true, .reload = .{ .file = "src/noise_walker.zig", .old = ".fill = .gray(127)", .new = ".fill = .gray(220)" } },
+ .{ .name = "bouncing_ball", .timeline = true, .reload = .{ .file = "src/bouncing_ball.zig", .old = ".fill = .gray(127)", .new = ".fill = .gray(30)" } },
+ .{ .name = "accel_to_mouse", .timeline = true, .reload = .{ .file = "src/accel_to_mouse.zig", .old = "s.position, 24, ball", .new = "s.position, 12, ball" } },
+ .{ .name = "fluid_resistance", .timeline = true, .reload = .{ .file = "src/fluid_resistance.zig", .old = "sk.Color.gray(220)", .new = "sk.Color.hex(0x99ccff)" } },
+ .{ .name = "angular_forces", .timeline = true, .reload = .{ .file = "src/angular_forces.zig", .old = "sk.Color.gray(175).alpha(200)", .new = "sk.Color.hex(0xdd3333).alpha(200)" } },
+ // batch B
+ .{ .name = "the_wave", .timeline = true, .reload = .{ .file = "src/the_wave.zig", .old = "sk.Color.gray(127).alpha(127)", .new = "sk.Color.gray(30).alpha(127)" } },
+ .{ .name = "pendulum", .timeline = true, .reload = .{ .file = "src/pendulum.zig", .old = ".fill = .gray(127)", .new = ".fill = .gray(220)" } },
+ .{ .name = "system_of_systems", .timeline = true, .reload = .{ .file = "src/system_of_systems.zig", .old = "sk.Color.gray(127).alphaFloat(a)", .new = "sk.Color.hex(0xc03020).alphaFloat(a)" } },
+ .{ .name = "flow_field", .timeline = true, .reload = .{ .file = "src/flow_field.zig", .old = ".fill = .gray(127)", .new = ".fill = .hex(0x3070d0)" } },
+ .{ .name = "flocking", .timeline = true, .reload = .{ .file = "src/flocking.zig", .old = "f.shape(&bodies, .gray(127));", .new = "f.shape(&bodies, .hex(0xd04020));" } },
+ .{ .name = "wolfram_ca", .timeline = true, .reload = .{ .file = "src/wolfram_ca.zig", .old = "}, 0x000000);", .new = "}, 0x2050c0);" } },
+ // phase 3: render-features
+ .{ .name = "smoke", .timeline = true, .reload = .{ .file = "src/smoke.zig", .old = "sk.Color.white.alphaFloat", .new = "sk.Color.hex(0xffa040).alphaFloat" } },
+ .{ .name = "additive_blending", .timeline = true, .reload = .{ .file = "src/additive_blending.zig", .old = "const magenta = sk.Color.hex(0xff64ff);", .new = "const magenta = sk.Color.hex(0x40c0ff);" } },
+ .{ .name = "recursive_tree", .timeline = true, .reload = .{ .file = "src/recursive_tree.zig", .old = ".stroke = .black, .width = 2", .new = ".stroke = .hex(0x2a7a2a), .width = 2" } },
+ // phase 3: lib-features
+ .{ .name = "path_following", .timeline = true, .reload = .{ .file = "src/path_following.zig", .old = "sk.Color.black.alpha(55)", .new = "sk.Color.hex(0x3070d0).alpha(80)" } },
+ .{ .name = "quadtree", .timeline = true, .reload = .{ .file = "src/quadtree.zig", .old = ".stroke = .hex(0xff3232)", .new = ".stroke = .hex(0x3232ff)" } },
+ .{ .name = "koch", .timeline = true, .reload = .{ .file = "src/koch.zig", .old = "vec.Affine.rotate(-std.math.pi / 3.0)", .new = "vec.Affine.rotate(std.math.pi / 3.0)" } },
+ .{ .name = "lsystem", .timeline = true, .reload = .{ .file = "src/lsystem.zig", .old = "std.math.degreesToRadians(25.0)", .new = "std.math.degreesToRadians(35.0)" } },
+ .{ .name = "flappy_bird", .timeline = true, .reload = .{ .file = "src/flappy_bird.zig", .old = "pipe_pen: sk.draw.Pen = .{ .fill = .black }", .new = "pipe_pen: sk.draw.Pen = .{ .fill = .hex(0x2a8a2a) }" } },
+ // phase 3: vector-perf
+ .{ .name = "bin_lattice", .timeline = true, .reload = .{ .file = "src/bin_lattice.zig", .old = "f.shape(&bodies, .gray(127));", .new = "f.shape(&bodies, .hex(0x3070d0));" } },
+};
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+ const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize });
+
+ // `-Dsketch` picks the one `run`, `lib` and `web` use; `e2e` plays them all.
+ const selected = b.option([]const u8, "sketch", "The sketch to run (default random_walk)") orelse sketches[0].name;
+ const steps = sb.app(.{ .name = selected, .root_source_file = b.path(b.fmt("src/{s}.zig", .{selected})) }).addSteps(.{ .web = .{ .assets = &.{.{ .source = b.path("assets"), .dest = "assets" }} } });
+ for (sketches) |s| {
+ const app = sb.app(.{ .name = s.name, .root_source_file = b.path(b.fmt("src/{s}.zig", .{s.name})) });
+ const exe = app.addScriptExecutable();
+ b.installArtifact(app.addExecutable());
+ steps.e2e.dependOn(&app.addScript(exe, b.path(b.fmt("test/{s}.script", .{s.name})), .{}).step);
+ if (s.timeline) steps.e2e.dependOn(&app.addScript(exe, b.path(b.fmt("test/{s}.timeline.script", .{s.name})), .{}).step);
+ if (s.reload) |edit| steps.e2e.dependOn(&app.addReloadCheck(.{
+ .script = b.path(b.fmt("test/{s}.reload.script", .{s.name})),
+ .edits = &.{edit},
+ }).run.step);
+ }
+}