Genetic Algorithms: Approximating Fine Art
For a bit of fun, I decided to re-implement Roger Alsing’s approximation of the Mona Lisa in Ruby (my language of choice).
Rather than the brute force approach taken by the original implementation, I’ve gone for a full genetic algorithm solution, with crossover, mutation and population propagation. It’s been lots of fun :)
If you’re interested, grab the code here. It’s all open source: if you fancy modifying it, feel free to do so!
Update: Added work in progress image.
Update: Replaced work in progress image. This one only uses 50 triangles!


This is awesome. You totally saved me from having to do it myself. :)
I’m curious about the opengl you require. On my system, I had to include gl and glut (from ruby-opengl) and then change all of the Gl and Glut methods and constants to their class versions. It was all very easy, but I’m wondering what you’re using.
That’s weird – I just did a simple
gem install ruby-opengl…Thanks for looking – feel free to submit patches!
The
ruby-openglgem works for me.Very odd. Did the same thing here but it didn’t like it. Using OSX here. I wonder if it’s a platform thing.
Either way, it’s a great start. I’m having fun working on improving it.
Works on Windows too – you need to install the rmagick-win32 gem manually (see http://rmagick.rubyforge.org/install-faq.html#win) and run the ImageMagick installer which is bundled with the rmagick-win32 gem.
I’ve now replaced the image with a better one, only using triangles!
For some reason, the more constrained the sizes and opacity of the polygons are, the better the result. One side of a triangle can be max 25% of the screen, and they can be max 10% opacity. I guess better results come from the group rather than one triangle coming to dominate the image.
I got it running on Ubuntu, though I had to use Synaptic to grab the ruby-opengl and rmagick packages first. I then did the gem install, just to be sure.
I left it to run for about 10 minutes, and it only got through about 700 generations on a 276×429 jpeg. Is that normal?
Yeah, fairly normal. Speed is really a function of the population size, so if you want a faster iteration time then decrease that number. You run greater risk of hitting local minima if you do that though, although the ‘nuke’ option added later does help mitigate that.
Development of digital technologies occurs prompt rates. Does not lag behind progress and digital TV. Speaking about digital TV, we first of all mean satellite TV. The digital satellite TV becomes more and more accessible to simple users. The market paid satellite tv also is not necessary on a place. The new digital standard of TV of high clearness HDTV actively develops and takes root. The satellite TV becomes more and more directed on the spectator. Besides digital quality of the image, advantage of satellite systems also is also the extensive cover zone of the companion.
just continue doin good and you will know the result