As a creative art enthusiast born without any artistic skills, I saw the launch of DALL-E and others as an opportunity to cover my entire apartment with “my” masterpieces without the need for master a paintbrush.
This was not the case and my walls remain a blank canvas. I failed to create anything display-worthy, but more importantly, DALL-E killed the mood.
For what?
Because most of the magic in art comes from feeling your way through the creative process. It’s a journey, not just an outcome. AI art felt too dictated, too random, and too cold.
So this got me thinking: is there a happy medium? Is there a way to have random but controlled generative art and still get that dopamine/pride moment of a finished piece? And it goes without saying, without real artistic skills?
In this article I’ll show you how I created two museum-worthy works of art and we’ll find out who Mondrian’s imposter is.
For my first work of generative art, I was inspired by Piet Mondrian, a pioneer of abstract art. His work is presented as an abstract arrangement of lines, colors and shapes.
Here is a small sample of some of his most iconic pieces:
Do you already know which one is the imposter?
If you want to try it, just install the “maker of Mondrian“Python package for painting new parts like this:
The mondrian-maker package was created by Andrew Bowen and is released under the GNU General Public License.
from mondrian_maker.mondrian import mondrianm = mondrian()
m.make_mondrian()
Part of the fun is that a new part will be generated every time you call make_mondrian(). Not all of them will be “paint-worthy” so I generated 100 and picked my favorites.
for i in range(0,100):
f,ax=m.make_mondrian()
f.savefig(f"{i}_mondrian.png")
And the answer to Python or the original game? The imposter is the the third from the left😉. The rest of the pieces are (from left to right): Composition No. I with red and blue (1938); Composition with red, yellow and blue (1942); Composition No. 10 (1939)
Did you guess correctly? Let me know in the comments!
Keep reading if you want to know how to recreate another thousand-dollar work of art:
Although Mondrian’s work really caught my attention, I wanted to start from scratch and create something of my own. That’s why I turned to Josef Albers Tribute to the Square series. I’m drawn to the way he played with perspective and color, and there’s something about the “simple” look that feels like the right place to dive. Judge for yourself:
Now, before you start drawing squares, you need to know two key secrets of Python generative art:
- Reproducibility: We want our art to be random but also be able to regenerate the exact painting. Using numpy.random.seed() we can ensure that the random numbers remain the same across runs.
import numpy as npconstant=12
np.random.seed(constant)
# From now on all generated random numbers are reproducible if constant=12
# To get different random numbers, choose a new constant
- Color theory: Artists use color combinations to generate visually appealing color palettes. The coding secret for this is to use MetBrewera Python library that contains 56 magnificent palettes inspired by works from the Metropolitan Museum of Art in New York.
from met_brewer import met_brew
palette=met_brew(name="Hokusai3", brew_type="discrete")
🎨Now we are ready to start painting!🎨
Spoiler alert: the next few code blocks reveal how to create a Homage to the Square lookalike painting, ignore them if you’d rather try it yourself first.
1- I first construct a function that generates the following:
- The 4 edges of a square (x0,x1,y0,y1)
- A random color for each square
from numpy import randomdef rectangle_generator(palette):
rectangle=()
big={'x0': 0, 'y0': 0, 'x1': 1, 'y1': 1,'color':palette(random.randint(len(palette)))}
rectangle.append(big)
middle={'x0': 0.1, 'y0': 0.05, 'x1': 0.9, 'y1': 0.85,'color':palette(random.randint(len(palette)))}
rectangle.append(middle)
small={'x0': 0.2, 'y0': 0.1, 'x1': 0.8, 'y1': 0.7,'color':palette(random.randint(len(palette)))}
rectangle.append(small)
tiny={'x0': 0.3, 'y0': 0.15, 'x1': 0.7, 'y1': 0.55,'color':palette(random.randint(len(palette)))}
rectangle.append(tiny)
return rectangle
2- I then plotted each square coordinate with Plotly
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
from met_brewer import met_brew
import plotly.io as pio#For reproducibility
np.random.seed(73)
#Choose a beautiful palette from met_brewer
palette=met_brew(name="Morgenstern", n=30,brew_type="continuous")
# Generate rectangles with defined palette
rectangles=rectangle_generator(palette)
# Plot!
# Setting canvas
fig=go.Figure()
fig.update_layout(
autosize=False,
width=800,
height=800,
)
fig.update_xaxes(range=(0, 1), showgrid=False,visible=False)
fig.update_yaxes(range=(0, 1),visible=False)
# Start painting
for rect in rectangles:
fig.add_shape(
type="rect",
x0=rect('x0'),y0=rect('y0'),
x1=rect('x1'),y1=rect('y1'),
line=dict(color=rect('color'),
width=2,),
fillcolor=rect('color')
)
fig.update_shapes(dict(xref='x', yref='y'))
fig.show()
pio.write_image(fig, "73morgensternplot.png", format="png", width=800, height=800, scale=3)
And here is the final result!
Let me tell you why I really enjoyed designing this piece of art – and why I hope you do too:
First, I had to crack the code on the square’s dimensions, making sure they matched the perspective of the original piece. Then came the fun (and slightly obsessive) part: playing with color palettes while waiting for that magical “aha” moment when everything clicked.
I didn’t stop there. I generated over 100 paintings with different starting constants, essentially becoming my own art curator and finding “the one”.
The best part? I was able to avoid hours of frustration painting and finally ended up with something “ok”. And I was not disappointed with an overrated Gen-AI tool. Instead, I let my imagination run wild and created a piece that I would be proud to hang on my wall – or even buy.
In my opinion, art looks higher and more expensive with a frame on:
This is the first article in a new series: From code to canvas. I’m open to suggestions on what artwork you’d like to recreate through code, so please leave a comment! And don’t forget to follow: your empty walls will thank you.
All images in this article are by the author, except for works by Piet Mondrain which are in the public domain.