Genetic Artist
The genetic algorithm repaints a target image one brushstroke at a time, searching for the stroke that brings the canvas closest to the picture.
Go to the live page Open the Genetic Artist demoThe Genetic Artist starts with a blank white canvas and a target picture, and paints its way toward the picture one brushstroke at a time. Before each stroke it runs a small genetic algorithm to find the single best stroke to add next. Early strokes lay down broad patches of colour; later ones sharpen edges and detail.
Targets and Brushes¶
Pick one of five target pictures: Pyramids of Giza, Mona Lisa, Nature, Sunset or Ancient Cairo. You choose the target before you start; the picker is locked while a run is painting.
In Settings you also pick one brush shape: Round, Dab, Flat (the default), Filbert, Fan, Curve, Thin Line, Speckle, Scratchy or Streak. Every stroke in the painting uses that brush. All brushes are hard-edged, so they differ only in shape.
How a Stroke Is Chosen¶
Each candidate in the population describes one stroke with five genes: which brush, where it goes across and down, how big it is, and its rotation angle. The colour isn't a gene. It is picked up from the target picture at the centre of the stroke, which keeps the search small.
Fitness tries each candidate stroke on a copy of the current canvas and measures how close the result is to the target, pixel by pixel. The closer, the better. After the search, the best stroke is painted onto the canvas only if it actually improves the match; if it doesn't, it is thrown away. Then a fresh search starts for the next stroke.
How a Run Looks¶
Click Start. The painting updates as strokes land, next to the target. The readouts show:
- Strokes. How many strokes have actually been painted. Searches whose best stroke was thrown away don't count here.
- Generations. Every generation run so far, counting all searches, kept or not.
- Improvement. How much the pixel error has dropped compared with the blank canvas, as a percentage. A chart tracks it over the run.
- Time left. How long until the run time limit stops the run.
You can pause and resume at any time, or reset to start over. A run stops by itself when it reaches the time limit or the stroke limit, and the status line says which one. If something goes wrong on Vilvik's side, the status says so and asks you to press Reset and try again.
Settings to Try¶
- Generations per stroke (5 to 50, default 15). Each stroke is searched harder, but fewer strokes fit in the time budget.
- Population size (5 to 50, default 20). How many candidate strokes are tried each generation.
- Mutation rate (0.05 to 1, default 0.25). The chance that each gene is replaced during mutation. Higher means more exploration.
- Max run time (30 to 180 seconds, default 60).
- Max strokes (50 to 1500, default 1000). This caps the number of stroke searches, including ones whose stroke was thrown away, so the Strokes readout can end below it.
Apply saves your settings for the next Start; Apply & Reset applies them and restarts the run.
What the Achievement Rewards¶
Signed-in users unlock the Master strokes achievement when a run finishes, by reaching its time or stroke limit, with an Improvement of at least 40 percent. Resetting before the run finishes doesn't count.
For more on how the demos catalog works, see What the Demos Do.