Mondrian
When I was a feckless youth I enjoyed cellular automata and procedural generation more generally. One day I had a fun idea for an algorithm that would generate regions of colour separated by black lines, somewhat reminiscent of the art of Piet Mondrian1.
Because I was a feckless youth I had the time and energy to actually implement these silly little ideas. The code for the toy is on GitHub; it's a Windows screensaver.
The central idea, expressed imprecisely2, is this:
- There are some number of randomly placed coloured pixels3.
- Every tick, every coloured pixel expands to every white pixel around it (including diagonals).
- If a pixel ends up next to two differently-coloured pixels, it instead turns black and fires a border head in the direction of each orthogonally adjacent white pixel.
- Border heads move in their direction, leaving behind a black pixel.
- If a border head hits a black pixel it dies.
- If a border head hits a coloured pixel, it splits into two new border heads travelling orthogonally to it.
- While there is a live border head, we only process borders, not coloured pixels. The border heads are effectively "instant"; we don't tick them slowly.
The original code was pretty terrible and had a few bugs. In March 2026 I thought I'd test out these fancy new models that were allegedly decent at programming now, so I pointed one at the code and asked it to modernise it and fix any bugs - it did a reasonable job4! Then I asked for a javascript version, which I now present to you below:
You'd have a running demonstration of the automaton here if you had javascript.
-
Why Mondrian? I don't remember, precisely. I don't think I'd had any particular connection to his art before. My best guess is that it was an outgrowth of my interest in esoteric programming languages, via the language Piet5.↩︎
-
There are also some "coloured pixels" that are white; this leads to more white spaces with borders around them.↩︎
-
I believe it was Opus 4.6. And yes, the code is still pretty ugly; poor old Claude was working with what it had. I assure you it's my fault in this case.↩︎
-
For what it's worth I don't think Piet programs look much like Piet's art at all. But I don't have the art knowledge to suggest someone more fitting...↩︎