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 guest@mondrian.byobu.co
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!

:-Dustin

5 comments:

  1. Interesting tie in with Google. Mondrian was the original name of their code review tool now called Rietveld (named after a Dutch architect and designer):

    http://code.google.com/appengine/articles/rietveld.html

    Gerrit - their code review tool based on this for Android is the first name of Mr Reitveld.

    ReplyDelete
  2. this is a truly great post!!
    as an engineer and art lover as yourself, i really appreciated it!
    mondrian's one of my favourites, too.

    ReplyDelete
  3. Have you seen the BBC Series "Hustle"? They did a GREAT episode on Mondrian, Season 1 - Episode 3.

    http://www.imdb.com/title/tt0608707/

    When I watched the episode, I thought the writers just made up the artist "Mondrian"... :-)

    ReplyDelete
  4. You might also be interested in the article "Piet (programming language)" on Wikipedia :)

    ReplyDelete
  5. It's misspelled "Modrian" in the menu->help-quickstart guide in byobu 5.17.
    Nice easteregg. I also like how hitting return merges cells. What are keyboard shortcuts to quickly generate a new one / quickly return to the normal view?

    ReplyDelete

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin

Printfriendly