Generates images from strings using a randomly grown expression tree.
Common types and algorithms shared across the whole project:
Node: the ASTGrammar: probabilistic tree generationPixelBuffer: flat RGB image bufferStatistics: tree analysisRng: seeded random number generation
Execution backends. Each one does exactly one thing: take an AST and return a PixelBuffer.
- metal: compiles the AST to Metal Shading Language and runs it on the GPU
- cranelift-jit: JIT-compiles the AST to native code via Cranelift
- closure-tree: interprets the AST as a tree of Rust closures
- llvm-aot: Uses the Rust build system to generate the AST as Rust native code, compiles, and runs it.
The CPU backends use the CORE-MATH project for their math implementations of functions not guaranteed by IEEE 754 to be correctly rounded. The Metal backend currently does not support this because it doesn't have native support of
f64. The Metal output may not be bit-identical to the CPU output.
Owns all I/O. Parses CLI arguments, invokes a backend, and saves the resulting PixelBuffer as a PNG. Optionally writes the formula as JSON.
Build a binary for the backend you want:
cargo build --release --bin randomart-metal
cargo build --release --bin randomart-cranelift
cargo build --release --bin randomart-closure-treeGenerate an image from a string seed:
./randomart-metal generate "hello world" 10depth controls how deep the expression tree is allowed to grow. Higher depth means more complex images.
Save the formula as JSON alongside the image:
./randomart-metal generate "hello world" 10 --save-jsonThis writes a .json file next to the PNG. You can then re-render from it later:
./randomart-metal read formula.jsonOther options for generate:
--width <WIDTH> Image width in pixels [default: 512]
--height <HEIGHT> Image height in pixels [default: 512]
--out <OUT> Output filename stem [default: the input string]
Output is always written to the current working directory. Pass --help to any binary or subcommand for full usage.