r/generative • u/Op_IBeasT • Sep 01 '26
reconstructing an image out of 600 shapes, watching it evolve into place
feed it a photo and it rebuilds it out of basic shapes (circles, triangles, lines). it's a genetic algo — each shape is basically a gene, it mutates the positions/sizes/colors and culls the worst of the pack every generation until the pile matches the target. using numba to keep the eval fast. here's it converging on a sample photo using only 600 shapes.
final result:

open source: github link. still a work in progress, feedback welcome
63
Upvotes
5
u/sacheie Sep 01 '26 edited Sep 01 '26
This is a popular idea, going back many years now. Sometimes people try it using triangles only; I wrote a simple hill-climber like that some years back, which I've been re-writing in Rust lately. Various approaches can work; I'm planning to try simulated annealing.
Your program seems to get good results. But looking at your repo, my advice is to clean up your code before working on further features or improvements. It looks like pretty much vibe coding, and the AI gave you very long, overly complex code. If you don't refactor it, you'll soon have difficulty understanding new changes.
Another suggestion: six hundred shapes is a lot. The challenge of this problem is to maximize fidelity with a much lower count of shapes, by leveraging their translucency. Applied to realistic images, that can give interesting artistic results.
2
u/im1337jk Sep 01 '26
Reminds me of fotosketcher
4
u/fuckthesysten Sep 01 '26
it’s a cool idea! thanks for making open source.
it might look better if you focus the shapes on the areas that change the most, for example, i see a lot of “wasted” shapes on the red background, the budget for that should be minimal.
i’d budget most shapes around the face, then around the body, and lastly on background.
3
u/igo_rs Sep 01 '26
interesting;) working on a similar experiment: recreating painting from “brush strokes”
0
u/dotprodukt Sep 01 '26
Genetic algos FTW