We set out to algorithmically generate art inspired by Piet Mondrian’s distinctive style — bold black lines,
primary colors, and clean geometry. While the aesthetic appears simple, recreating its visual harmony
through code required balancing randomness with structure. Our initial methods used recursive grid partitioning,
but the results often felt too uniform or mechanical.
To better capture the organic feel of Mondrian’s work, we turned to a brute-force approach: splatting.
This method randomly places rectangles onto the canvas, accepting or rejecting them based on simple aesthetic
rules like shape, size, and position. Though less elegant from a computer science perspective, it was easier
to evaluate good rectangles than to generate them deliberately — and the resulting compositions had a more
natural, expressive quality.
For color, we used the four color theorem. By modeling the rectangles as nodes in a planar graph, we can ensure
that no two adjacent regions share the same color. The classic Mondrian palette includes just four colors,
red, yellow, blue, and white. Using only these in strict alternation looked weird and didn't look like Mondrian's work.
To solve this, we introduced fake additional colors in the algorithm and then reassigned them to white, creating a more visually balanced
and aesthetically pleasing output.
All of this was then wrapped up in a python script and deployed to Azure Functions. The function is triggered by an HTTP request
and returns the generated image as a base64 encoded string, which is then rendered in your browser. There were several alternative
ways to implement this, but this was a relatively straightforward and cost-effective approach.
If you'd like to learn more about the algorithm, check out our blog post on the details: Making a Mondrian, Old School Generative Art.