From the Canyon Edge -- :-Dustin

Wednesday, March 7, 2012

Byobu is Celebrating Piet Mondrian's 140th Birthday

A little while ago, I added a fun Easter Egg to Byobu, in honor of one of my favorite artists, Piet Mondrian [Wikipedia, Artsy].

All day today, you'll be able to ssh into a shared Byobu session in HP's OpenStack cloud and see the Easter Egg in action!
  • ssh
The password is piet.

March 7, 2012 happens to be Piet Mondrian's 140th birthday!

For an engineer and a scientist, I'm probably more of an art lover than most.  I studied art history a bit in college, and even worked for the art department at Texas A&M University, which earned me a few free art classes over my usual engineering workload.  I generally seek out both boutique art galleries and the big ones when traveling.  All that said, Piet Mondrian is one of my favorite artists.  His lines, colors, proportions, precision, balance, symmetry and asymmetry speak to a part of my soul that's hard to explain.

You might recognize some of these, as his most recognizable works:

In the spirit of Google Doodles, I thought I'd call attention to Byobu's Piet Mondrian function quietly nestled in Byobu.  If you're running byobu in tmux mode (which you can launch with byobu-tmux), then you can simply press ctrl-alt-F12 in most environments (my sympathies if you're off the beaten path).  You should see something like this:

This is the output of the 116 line shell script found at /usr/lib/byobu/include/mondrian.  I don't think I've ever narrated my source code in my blog before, but I reckon I will do so here.  It's not that I'm particularly proud of the implementation or the code, but rather that I'd like to explain the algorithm I have applied to Mondrian's art :-)
  1. First, it hardcodes the color values of red, yellow, blue, and white from a 256 color palette.  To do so, I used the color picker utility in gimp against Mondrian's Composition 10, 1939–1942.
  2. Next, it chooses some random number of rectangles between 10 and 40, which seemed to me to be fairly representative of most of Mondrian's geometric compositions.
  3. Then, from the randomly numbered rectangles, 3 are chosen -- 1 for red, 1 for yellow, and 1 for blue.  I fully well appreciate that Mondrian put far more thought into what regions where colored, and which color, how much, with great precision and balance.  I hope one day to decode his algorithm, but for now, my code simple chooses these at random.
  4. Now, tmux does a bit of the hard work for us, creating a new window in byobu, sets the background to our particular white, and splitting that window into a number of panes matching our randomly chosen amount.
  5. Finally, one pane each is colored red, yellow, and blue.  Note that tmux does not support the classic UNIX terminal feature bce (background color erase), so instead, we use a one-line perl script to color each pane.
And there you have it!  A random approximation of a Mondrian composition right there in your terminal!

Here's a few images produced by implementation of the algorithm above...

Now surely I'm not the first programmer/art-lover who has tried to reproduce Mondrian masterpieces in source code?

Hardly!!! :-)

In 1966, Michael Noll of Bell Labs produced this incredibly interesting paper and research project, where his computer program produced a reproduction of a Mondrian work (Composition with Lines, 1917), and presented it to 100 human subjects.

Only 28% of the human subjects were able to determine the computer generated replica.  Somehow, 59% preferred the computer generated piece!  (I am not in that majority.)

So it seems I'm hardly the first, and Mondrian has been piquing the interest of computer programmers for at least 50 years.  To the contrary, it seems more likely to me that Mondrian was so far ahead of his time that he may have presupposed the precision and mathematics of computer generated images.

Hats off to you, Mondrian.  Rest assured that many, many people continue to enjoy your work, and it continues to inspire artists and engineers alike!