Generate Art

Pick a grid size and click Generate. The higher the grid size, the more complex and dense the piece is likely to be.
Generating the first piece may take a while (expect about 45 seconds), but every subsequent piece after should be much faster.

About the Project

The Mondrian Generator creates unique compositions inspired by the work of Dutch painter Piet Mondrian. By analyzing patterns, color theory, and geometric principles found in Mondrian's iconic abstract works, our algorithm generates new compositions that capture his distinctive style characterized by primary colors, black gridlines, and white spaces.

When you specify a grid size, the generator divides a canvas into sections and applies Mondrian's compositional rules to create a balanced yet unique artwork every time. This project represents an intersection of art history, computational aesthetics, and machine learning.

How It Works

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.