Monday, February 2, 2009

Mona Lisa image evolution in Ruby (JRuby)

Like several other people, I was fascinated by Roger Alsing’s post shortly before Christmas describing his program to evolve an image look like Leonardo’s Mona Lisa, using only semi-transparent polygons. This uses genetic programming (or perhaps more accurately, simulated annealing, a Monte Carlo method) to evolve an image, comparing each evolved image to its parent and deciding whether it is closer to the target image; if it is closer to the target, the image is retained and then evolved further.

Since Roger released his source code, there have been several other implementations in different languages, such as Javascript and Clojure. I thought that converting the program to another language would be an excellent way to understand how it works; so, I converted it to Ruby (actually JRuby, as Swing is used for drawing the images and the user interface).

I’ve uploaded the code to GitHub; my implementation is pretty much a straight port of Roger Alsing’s original code though, and generally speaking it’s a little quick and dirty; I may eventually spend a little time tidying and/or optimising it, but as of yet it isn’t either elegant or fast.

This short clip shows the evolution of the selected candidates over 75000 generations (around four hours on my machine).

posted by Nick at 8:50 pm - filed in java, ruby  

1 Comment »

  1. Dear Nick,
    As you seems to have a good command in different languages of programmation (I don’t have it) ,would you be interested to program a simulation of cells growing in different environment in order to demonstrate after multiple iterations (monte carlo method)the outcome of what we call in our biological slang a cellular darwinism.
    Each cell arbitrary will have only one gene coding for 3 different colors and their association ,plus different shapes (square, triangle,circle).
    Let me know if you want to discuss feasibility and study requirements.
    Looking forward hearing from you.
    Best regards

    Comment by Jean-Marc Leroux — October 1, 2009 @ 11:26 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment