No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Krzysztof Krystian Jankowski a8bf906392 Build with zig only: build.zig replaces build.ps1 / build.sh
One build for every platform (zig 0.16): `zig build` (app + assets in
zig-out/bin), `run`, `test` (selftest), `all` (the gate), `shot`,
`release` (optimised + stripped, zig-out/release), `html5` (emsdk,
zig-out/web), `serve`, `fetch` (pinned raylib commit via git, automatic
when missing) and `clean`. raylib is compiled into zig's cache per
target and mode; src/*.c is still globbed. The app builds with -Werror
because zig only shows C warnings when a compile fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 00:28:52 +01:00
assets the LAB: artificial-life workbench with tactical and realistic 3D views 2026-11-26 23:27:13 +01:00
docs Build with zig only: build.zig replaces build.ps1 / build.sh 2026-11-27 00:28:52 +01:00
extras the LAB: artificial-life workbench with tactical and realistic 3D views 2026-11-26 23:27:13 +01:00
src Bigger tanks, cube presets, roomier Setup tank panel, README shots 2026-11-27 00:28:52 +01:00
web Sharp HiDPI web UI, darker small labels, render fixes 2026-11-26 23:31:27 +01:00
.gitattributes the LAB: artificial-life workbench with tactical and realistic 3D views 2026-11-26 23:27:13 +01:00
.gitignore Build with zig only: build.zig replaces build.ps1 / build.sh 2026-11-27 00:28:52 +01:00
AGENTS.md Build with zig only: build.zig replaces build.ps1 / build.sh 2026-11-27 00:28:52 +01:00
build.zig Build with zig only: build.zig replaces build.ps1 / build.sh 2026-11-27 00:28:52 +01:00
README.md Build with zig only: build.zig replaces build.ps1 / build.sh 2026-11-27 00:28:52 +01:00

the LAB — artificial-life workbench

A laboratory-style tool for experimenting with evolution in a 3D tank. Simple cellular organisms (one per 1.7 cm voxel, Game-of-Life-style neighbour rules) live in an editable environment of water, sand and air, harvest light or nutrient, divide, mutate, speciate into colour-coded lineages — and learn: each organism tunes a small movement policy during its life (reward-modulated), while its children inherit the genetic version (Baldwinian evolution).

The tank is furnished: rocks and driftwood are solid (shade, walls, territory borders), plants root in the sand, grow toward the light and bear fruit, and food sources keep a pile of food topped up until they run dry. Foraging works like an ant colony: food gives off a diffusing scent, carriers lay a food trail on their way home, searchers lay a home trail, and each organism learns how much to trust the scent and the trails. Lineages also fight over territory and food: an aggression trait decides who attacks, colonies and burrows defend, winners loot the loser and take its cell. Raids show up in the event log and the Conflict chart.

Burrowers can dig: an evolvable digging trait lets them excavate the sand (eating the organic matter in it) and carry the spoil out to mounds round the entrance, instead of pushing through the sediment. The sand is a voxel mass with simple granular physics: nothing floats, unsupported roofs cave in, damp sand holds steeper walls and wider tunnels than dry sand, slopes slump to an angle of repose, abandoned burrows slowly collapse, and tunnels below the water table flood (and drain with it). Burrows are damp, sheltered and easier to move through, and organisms learn to use them.

Simulation view, realistic look: a tidal shore with burrows against the glass

Tactical look with the section plane: flooded tunnels (blue) and dry burrows (brown) in the cut

Built in C11 + raylib 6.2 (OpenGL 3.3 desktop, WebGL2 web) on the Raylib Bootstrap shell (Classic and Aqua themes, Ctrl+T).

Views

  • Setup (F1): environment preset (Aquarium, Tidal shore, Lagoon island, Dry dunes, Divided tank - a ridge splits a rich basin from a poor one), tank size (Nano / Standard / Long / Tall / Large / Huge / Cube 40 / Cube 60, or custom W x H x D from 20 cm up to 200 x 80 x 100 cm, up to 24 000 organisms), seed, mutation rate, inherited learning, cellular rules. Apply & restart starts a new run.
  • Simulation (F2): two looks, switched with V or the viewport toggle. Tactical is built for reading the experiment: flat shading, sand contour lines every 2 cm, a crisp waterline, solid outlined organisms (x-ray outlines for burrowers, amber markers on food carriers, red flash in fights) and constant lighting. Realistic is a lab photograph: sun (tank lamp) shadow map, PBR materials with procedural sand / rock / wood, fake subsurface on leaves and organisms, SSAO, refractive jelly with coloured absorption, water with Beer-Lambert absorption, in-scatter, turbidity from the simulation, refraction and screen-space reflections, green-edged glass, a lab room environment, then depth of field, bloom, ACES and a film LUT (post ported from Raylib Bootstrap 3D). The 3D tank — translucent jelly organisms (vertex wobble, lobes, membrane fresnel), wave-animated water with caustics on the sand, procedural sand with wet/dry shading, nutrient inlet plume, lamp with a day/night cycle. CAD-style viewport: Iso/Front/Top/Side, dimension lines, axis triad, a section plane that cuts sand and water and maps a field (nutrient / light / moisture) on the cut with a colour bar. Tools: select, orbit, raise / lower sand, nutrient pulse, seed a lineage, erase, place props (rock, plant, food source, driftwood). Field overlays include food scent and pheromone trails. Charts (population, traits, habitat, conflict, evolution: learned vs genetic foraging, food deliveries, divergence of the two tank halves) and an event log below; the inspector shows the selected organism's genome, learned vs genetic behaviour weights and ancestry.
  • Analysis (F3): full-size history charts, the lineage table and a lineage inspector (founder vs current genome, descendants).

The left column holds the experiment tree (layer visibility), lineages (visibility, pick for seeding) and live environment controls: water level, temperature, light intensity and cycle, flow, nutrient input, sand humidity, inlet. Export the run history as CSV (Ctrl+E) or snapshot the viewport as PNG (Ctrl+P).

Keys: Space run/pause, . step, 1-8 tools, X section, B charts, Home reset camera, + / - / 0 zoom in / out / reset, V tactical / realistic, F follow selected, Del remove selected, F9 help. Viewport: right-drag orbit, middle-drag (or Space+drag, Shift+right-drag) pan, wheel zoom. Panels: middle-drag or Space+drag scrolls.

Code: sim.* life model (raylib-free, deterministic, headless selftest), scene.c renderer + shaders (GLSL 1.20 desktop / ES 1.00 web), view_*.c views, evo_ui.c app widgets, main.c menus/actions/left column. The bootstrap demo app lives in extras/demo/ for reference.

Quick start

One build for every platform: zig 0.16 (winget install zig.zig on Windows) plus git.

Platform Also needs Build + run
Windows - zig build run
Linux X11/GL headers (below) zig build run
HTML5 emsdk at ~/emsdk or $EMSDK zig build serve -> http://localhost:8080

Linux packages (Debian/Ubuntu):

sudo apt-get install build-essential git libx11-dev libxrandr-dev \
  libxinerama-dev libxcursor-dev libxi-dev libgl-dev

The first build fetches raylib into third_party/raylib (pinned commit, git-ignored) and compiles it once per target and mode into zig's cache; later builds only compile src/.

Commands (zig build <step>, see zig build --help)

Step What it does
(none) build the app into zig-out/bin/ (with assets/)
run build, then start (zig build run -- --theme Aqua passes flags)
test --selftest: validates themes, layout at 5 window sizes, app checks; no window, exit 0 = pass
all build + test: the gate before handing work back
shot --shot build/shots: PNG of every view in every theme + menu, dialog, phone and drawer
release optimised, stripped build into zig-out/release/ (exe + assets/)
html5 WebGL2 build into zig-out/web/ (index.html/.js/.wasm/.data)
serve html5, then a local HTTP server on port 8080
fetch fetch the pinned raylib source (done automatically when missing)
clean remove zig-out/ and build/ (keeps the raylib source)

Options: -Doptimize=Debug|ReleaseSafe|ReleaseFast|ReleaseSmall (default ReleaseFast), -Dtarget=..., -Dshots=DIR, -Demsdk=PATH. The app compiles with -Wall -Wextra -Werror (zig only shows C warnings when a compile fails).

The web build must be served over HTTP (browsers block file:// fetches). Deploy by copying the four zig-out/web/index.* files to any static host.

Run-time flags

thelab  [--theme Classic|Aqua]       start with a theme
thelab  --selftest                   headless checks (CI gate)
thelab  --shot DIR                   render every view x theme to DIR/*.png

L side column, I inspector, Ctrl+T next theme, Esc closes menus/dialogs.

Start your own app

  1. Rename: app_name in build.zig, APP_NAME in src/main.c.
  2. Delete src/demo_*.c + src/demo.h; keep lorem.* if you like fake data.
  3. Write views (see docs/UI.md): each is an AppView with work, optional toolbar and inspector draw callbacks.
  4. List views, menus and handlers in the AppConfig in main.c.
  5. Design a theme: copy src/theme_classic.c (see docs/THEMES.md), then zig build shot and look at build/shots/.

Minimal app:

#include "app.h"

static void hello(void *st, App *a, Rectangle r) {
  (void)st; (void)a;
  kit_backdrop(r);
  kit_title("Hello", r.x + 28, r.y + 40, 24);
  if (kit_button((Rectangle){r.x + 28, r.y + 70, 120, 32}, "Click", KB_PRIMARY, false, true))
    dlg_message("Hi", "Button clicked.");
}
static const AppView kHello = {.title = "Hello", .icon = KI_STAR, .work = hello};
static const AppView *const kViews[] = {&kHello};
static const AppConfig kCfg = {.title = "My App", .brand = "My App",
                               .views = kViews, .view_count = 1};
int main(int argc, char **argv) { return app_run(&kCfg, argc, argv); }

Built with it

  • ../wfc/ — WFC Studio, a Wave Function Collapse previewer and seed drawer: three views, a raylib-free algorithm core with a headless selftest and benchmark, drag & drop on desktop and web.

Documentation

  • docs/UI.md: the shell, views, layout, every widget, menus, dialogs, input rules, recipes.
  • docs/THEMES.md: the token list, shape/type switches, how to design and register a theme.
  • AGENTS.md: conventions and gates for coding agents.

Licences

raylib: zlib licence (fetched, not vendored). Fonts in assets/ (IBM Plex Sans, Inter): SIL Open Font License 1.1 (see assets/README.md).