🧪 We're running a cheminformatics notebook competition!

Enter by October 4
106 / 106
Circle Genetic Art

Circle Genetic Art

by marimo team

Rebuild an image from translucent circles or squares with a hill climber, and compare an all-at-once fit against a waves fit.

About this notebook

This notebook rebuilds a target image from translucent shapes with a hill climber. It holds the shape data in numpy, draws and composites the shapes with Pillow, and plots the charts with matplotlib. The target is an embedded Mona Lisa image, or an image that you upload.

Sliders set the shape opacity, the shape count, and a separate iteration budget for each strategy. A switch draws squares instead of circles. Press Evolve to run two strategies at the same time. The all-at-once strategy fits every shape together. The waves strategy fits a batch of shapes, freezes the batch, then fits the next batch over it. Both panels update while they run.

Each shape holds a position, a size, and a color, and starts with the target color at its center. Each step moves a few shapes and keeps the change only when the pixel error drops. Two charts plot the error against the step count and against the compute time, because a wave step costs less than an all-at-once step. A memo stores each finished run, so a change to one setting recomputes only the strategy that the change affects. The best result renders to a 768 pixel PNG that you can download.

Related notebooks