A multithreaded genetic algorithm written in Rust that reconstructs target images using overlapping semi-transparent polygons and ellipses. Over successive generations, individuals mutate and cross over to approximate the target image pixel-by-pixel.
Target (images/) |
Reconstructed Output (Root) |
|---|---|
Original: Charles Darwin![]() |
Evolved (~96.7% fitness)![]() |
Original: 9c![]() |
Evolved (~95.0% fitness)![]() |
- Parallel Evaluation: Scales across CPU threads with
rayonfor concurrent rasterization and fitness scoring. - Vector Rasterization: Uses
tiny-skiafor rendering semi-transparent paths and shapes directly into memory buffers. - Dynamic Hyperparameters: Automatically scales mutation steps, shape bounds, and survival thresholds as overall population fitness increases.
- Shape Variety: Combines variable-vertex polygons with bounding ellipses to capture both broad gradients and sharp edges.
Ensure you have a recent Rust toolchain installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shExecute with native CPU vectorization enabled in release mode:
RUSTFLAGS="-C target-cpu=native" cargo run --release -- <image_file> <generations> <population_size>Examples:
# Evolve darwin.png with 9000 generations and 300 individuals
RUSTFLAGS="-C target-cpu=native" cargo run --release -- darwin.png 9000 300
# Evolve 9c.png with custom generation limits
RUSTFLAGS="-C target-cpu=native" cargo run --release -- 9c.png 10000 500| Parameter | Default | Description |
|---|---|---|
image_file |
9c.png |
Name of the file inside images/ |
generations |
1000 |
Total generations to run |
population_size |
350 |
Number of candidate individuals per generation |
Final renders are written to the out/ directory with run parameters and the final fitness score in the filename:
out/{file_name}_{generations}_{pop_size}_{chromosome_count}_{fitness}.png



