Synthesizing turtle programs to redraw images with MCMC
โ Rust ๐ 2026-05-31 ๐ค surdeus ๐๏ธ 1I made a small Rust project called "morph"
It takes a image and tries to synthesize a turtle program that redraws it. Thereโs no neural net involved โ just MCMC search over a tiny DSL.
The program is a fixed-length sequence of commands like:
- Forward
- Turn / SetAngle
- MoveTo
- SetWidth
- SetColor
- NoOp
Each candidate program renders onto a 256ร256 1-bit canvas, and the fitness function is the Jaccard index between the rendered image and the target.
The fun part is that the result gradually improves the longer it runs. With 4 chains and a 3-hour budget, I got results around 0.95โ0.98 Jaccard on a few examples.
Itโs still rough and there are plenty of things that could be improved, so feedback is very welcome.
1 post - 1 participant
๐ท๏ธ Rust_feed