A computational graphics framework for generative art in Zig.
Sequences provides a sketch-based programming model for creating mathematical visualizations and algorithmic art. Write simulations in continuous space, accumulate results into rasters, and export high-quality images.
# Build and run a sequence
zig build sq -Doptimize=ReleaseFast -- rw1
# Run all tests
zig build test
# Check compilation
zig build checkEach sequence consists of:
.zig- Implementation using theContext(Config)framework.zon- Configuration file with runtime parameters
pub fn sequence(ctx: sq.Context(Config)) !void {
// Setup simulation space
const sim_rect = sq.Rect2.ofExtentCentered(ctx.config.frame);
var raster = try sq.GrayscaleRaster.init(ctx.allocator, pixel_extent);
// Run simulation
for (0..iterations) |_| {
const point = simulate();
if (sim_rect.contains(point)) {
const uv = sim_rect.getUv(point);
raster.splat(uv, intensity, .bilinear);
}
}
// Post-process and export
processor.processInPlace(raster.buffer);
try raster.writeToFile(ctx.allocator, "out.png", .{});
}Sequence Framework
Context(Config)- Provides services to your sequence:allocator- Memory allocationrng- Seeded random number generationconfig- Parsed configuration from .zon filenode- Progress tracking for long operationstimer- Performance measurement
Coordinate Systems
Extent2/Rect2- Floating-point geometry with physical dimensionsExtent2i/Rect2i- Integer pixel-space geometryUv2- UV coordinates [0,1)×[0,1)- Seamless conversion between simulation, UV, and pixel spaces
Rasterization
GrayscaleRaster- Accumulation buffer with point/bilinear/box filteringStdGrayscalePostProcessor- Tone mapping, normalization, inversion pipeline
Utilities
ReservoirSampler- Random sampling from streams
- Resolution independent - Work in physical units (inches), render at any DPU
- Memory explicit - All allocations use provided allocators
- Performance conscious - SIMD vectors, fused operations, progress reporting
- Test driven - Comprehensive tests for core components
See src/sequences/ for examples including:
rw1- Random walk/Brownian motion trailsif1- Iterated function systemsif2- IFS with nonlinear transformations
Each demonstrates different techniques for point generation, accumulation, and post-processing.