# Composition à la Mondrian

I would like to paint something like this

or,even better, like this

I have tried

colors =
{Red, Blue, Yellow, White, Black};

cells =
ConstantImage[RandomChoice[colors], #] & /@
RandomInteger[{50, 10}, {30, 2}];

ImageCollage[
cells,
Background -> Black,
Method -> "Rows",
ImageSize -> 400]


The result is unpleasing, especially because all rows have equal height.

How could one produce a more Mondrian - like image?

• It may be that the achievement of Piet Mondrian was obtained with an algorithm other than RandomChoice[colors] :) – rhermans Sep 13 '14 at 16:31
• Of course @rhermans :) - on view from apartment... Trees! How ghastly! (Piet Mondrian) – eldo Sep 13 '14 at 17:28
• Please consider using something like {RGBColor[0.9, 0.9, 0.9], RGBColor[0.05, 0.05, 0.05], RGBColor[0.8, 0.1, 0.1], RGBColor[0.1, 0.1, 0.5], RGBColor[0.9, 0.7, 0.1]}; it's closer to Mondrian's palette and easier on the eyes :) – user484 Sep 13 '14 at 18:55
• There is a "visual design" under the neat examples for grid that is a bit Mondrianish. – wxffles Sep 14 '14 at 20:57

This is a similar idea to ybeltukov's, iteratively splitting rectangles into two smaller rectangles. I've used an integer grid to avoid getting small offsets between adjacent blocks, and a weighted random choice to decide whether to split horizontally or vertically or do nothing. The idea is that long thin rectangles should preferentially be split along the long axis.

splitx[Rectangle[{x0_, y0_}, {x1_, y1_}]] :=
Module[{a = RandomInteger[{x0 + 1, x1 - 1}]},
{Rectangle[{x0, y0}, {a, y1}], Rectangle[{a, y0}, {x1, y1}]}]

splity[Rectangle[{x0_, y0_}, {x1_, y1_}]] :=
Module[{a = RandomInteger[{y0 + 1, y1 - 1}]},
{Rectangle[{x0, y0}, {x1, a}], Rectangle[{x0, a}, {x1, y1}]}]

f = ReplaceAll[
r : Rectangle[{x0_, y0_}, {x1_, y1_}] :>
RandomChoice[{(x1 - x0)^2, (y1 - y0)^2, 5} -> {splitx, splity, Identity}] @ r];

{{Black, White, Yellow, Red, Blue}, {0, 0.1, 0.1, 0.15, 0.3}}];

Graphics[{EdgeForm @ Thickness[0.012], {FaceForm @ RandomChoice @ cols, #} & /@
Flatten @ Nest[f, Rectangle[{0, 0}, {20, 20}], 6]},
AspectRatio -> 0.7]


• I am delighted. Your image is enchanting and your coding elegant. – eldo Sep 13 '14 at 21:47

An extended comment follows. Mondrian, in the late work referenced by the OP and characterized by primary colored rectangles separated by black lines, employed an extraordinarily sophisticated understanding of perception, color, and light.

As background to understand what Mondrian does, I recommend The Interaction on Color, by Joseph Albers and Alfred C. Barnes's, The Art in Painting.

The Albers book shows how one color affects another color. For instance, place two equally sized rectangles of two primary colors (red and blue) on a white page and the red will appear to come forward and the blue to recede. Varying the size, hue, saturation, and placement of the two rectangles relative to each other and to their position on the page can change an observer's perception of the relationship of the illusion. One can even make the red recede!

You can play with this bit of code to try it:

 Row[{
Graphics[{Red, Rectangle[{0, -1}, {2, 1}]}, ImageSize -> 200],
"         ",
Graphics[{Darker[Darker[Blue]], Rectangle[{0, -1}, {2, 1}]},
ImageSize -> 200]}]


The Albers book does a much better job of illustrating the point.

The Barnes book and even his collection displayed at the Barnes Foundation in Philadelphia, presents his deep thinking on the ideas that Albers illustrates. Barnes identifies a long tradition in painting that has has long explored these questions. (Note that the Barnes collection precedes Albers's work by a couple of generations).

Painters from Georgione followed by his student Titian followed by his student El Greco, followed in Spain by Velazquez, followed by Goya, followed by Renoir and the impressionists they influenced explored these ideas and communicated them in an unbroken line from the 1400s to the present day. A handful of painters, like Rembrandt, made their own contributions to this dialogue when they discovered these painters, paintings, and their line of inquiry and discovery.

All of this affects our perception of the world. What we see, indeed what our vision equips us to see, can often - if not always - contradict what we know of the world from moving through it. Painters and Mondrian himself endeavored to understand these paradoxes and employ what they learned in their work.

Titian used this to supply an observer of one of his paintings with the equivalent of what they would observe in nature. A kind of primary presentation of the visual data facts, which an observer's brain would recognize as equivalent to what they might see in the real world so that their brain would process the information in the same or a similar way as observing the real world. Look closely at a Titian and one will often see odd contradictions such as something that one know sits behind something physically painted on top of it.

Response to @belisarius's comment. I didn't have an image readily available from Titian, but I think this one from Velazquez (a great lover of Titian's work, he traveled to Italy to study them) illustrates the idea:

In the middle of the 3 images of the portrait, I've outlined two areas where Velazquez has actually painted the background physically on top (a top layer of paint) over the foreground image. In the left representation, I've circled a bravura red/pink brush stroke, which Velazquez added as likely his very last stroke on the painting. That warm reddish color pulls the entire left side of the picture forward to balance the prominence of the central figure. In this Velazquez has made precisely the same kinds of choices based on the interaction and relationship of color that Mondrian does. Without these "contradictions" to what we know of the world from moving through it, the figure would appear lost in a vacuum. Among other things Velazquez has managed to convey the volume of space between the observer and the observed. Velazquez (and Mondrian) sees all as light. Background and foreground all in the eye at once. For him material has/is light/color. One can see this Portrait of Juan de Pareja in person at NY's Metropolitan Museum of Art.

Lesser painters who don't understand these ideas render what they think they know rather than the unfiltered data. Their paintings will often appear cartoonish or just dead when compared to those of painters who have thought about all of this.

In his late work, Mondrian, like any good scientist or mathematician reduces these ideas to a model, an abstraction in which he can explore and better understand them.

Consider this sequence of paintings that span his entire career...

One can see Mondrian reducing his model - abstracting his understanding of perception.

Look closely at an actual painting and one can see how Mondrian has labored to adjust the size and color of all of the different rectangles. Each of these paintings took months to create. In almost all of these late works, Mondrian balances each element of the pictures so that they all hover perceptually on the same plane (something which color in the real world does irrespective of what we "know" about the location of the objects it defines.)

It is truly brilliant work in both the realm of art and science.

All of this goes to thinking about what one really needs to understand to create an algorithm that might produce a Mondrian that Mondrian didn't get around to painting.

One last thing maybe worth illustrating, offered without further comment:

Piet Mondrian: Composition in grey and brown with overlay.

A couple more last things - links to journal articles about Mondrian that may prove interesting:

and

Mondrian's Search for Geometric Purity: Creativity and Fixation, by Bennet Simon.

20 June 2016 (NOT 2015;-) Update ...

In New York, the Metropolitan Museum of Art's new Breuer location at 74th & Madison Ave. has an exhibition based on the idea of "unfinished" paintings.

The show displayed 2 very interesting late Mondrian works:

The paintings show early stages of the kinds of paintings that inspired the OP's questions. I find the first particularly interesting as Mondrian, begins the "painting" with masking tape thumb tacked to the canvass. Mondrian's equivalent of a Manipulate model to explore possibilities.

• Nice answer (or comment, whatever). Examples of Titian's "contradictions" would be great! – Dr. belisarius Sep 13 '14 at 20:20
• @belisarius - re: Titian take a look at this link from the Frick collection in NY. You can zoom around the painting and see lots of this kind of thing. – Jagra Sep 14 '14 at 0:12
• @Jagra, remove this dispensable piece of code and your answer will be the most extraordinary one on this site :) – faleichik Sep 16 '14 at 10:46
• @Mr.Wizard - Really, 2016? Haven't lifted my head from the code for months ;-) – Jagra Jun 20 '16 at 16:45
• Well, I'm sorry to say that the art history behind this answer is entirely bogus. Piet Mondrian was not exploring the interactions in color a la Josef Albers. In fact, Mondrian restricted his palette to red, blue and yellow blocks of color (with occasional black, and of course white) so as to restrict his explorations of color. He eliminated all "natural" colors (brown, green, ...) to avoid referencing nature. He was far more interested in the rules of composition, and you can see here (spie.org/Publications/Proceedings/Paper/10.1117/12.840558). It is "Breuer" (not Bruer). – David G. Stork Mar 27 '19 at 23:53

Here is my attempt to be Piet Mondrian

colors = {RGBColor[0.9, 0.9, 0.9], RGBColor[0.05, 0.05, 0.05],
RGBColor[0.8, 0.1, 0.1], RGBColor[0.1, 0.1, 0.5], RGBColor[0.9, 0.7, 0.1]};

split = # /. d : Rectangle[{x1_, y1_}, {x2_, y2_}] :>
With[{t = RandomReal@BetaDistribution[10, 10], r = Random[]}, Which[
r < 0.3 (x2 - x1)/(y2 - y1),
{Rectangle[{x1, y1}, {x1 + (x2 - x1) t, y2}],
Rectangle[{x1 + (x2 - x1) t, y1}, {x2, y2}]},
1 - r < 0.5 (y2 - y1)/(x2 - x1),
{Rectangle[{x1, y1}, {x2, y1 + (y2 - y1) t}],
Rectangle[{x1, y1 + (y2 - y1) t}, {x2, y2}]},
True, d]] &;

Nest[split, #, 7] &@ Graphics[{EdgeForm@{Thickness[1/150], RGBColor[0.05, 0.05, 0.05]},
Rectangle[{0., 0.}, {1.4, 1.}]}, ImageSize -> 700] /.
r_Rectangle :> {RandomChoice@colors, r} /. x_Real :> Round[x, 0.05]


Here is some tweaks with random numbers to obtain more uniform splitting. Then one can easily rasterize the result. By default antialiasing is disabled and lines will be perfectly aligned to pixels like in the above image.

Update: nice Rahul Narain's colors and aligning boundaries by rounding of the coordinates.

• Thank you so much. There is much to learn from your excellent solution. – eldo Sep 13 '14 at 21:58