Synthesizing turtle programs to redraw images with MCMC

โš“ Rust    ๐Ÿ“… 2026-05-31    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

I 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

Read full topic

๐Ÿท๏ธ Rust_feed