Saturday, October 30, 2010

Evolving Wallpaper for Ubuntu

Id been planning on learning image processing in python (or rather, using PIL, numpy and scipy) and so when I saw this, it was the perfect opportunity. I have forever been fascinated with cellular automata and in particular, Conway's Game of Life. Though I was never a fan of biology in school, there was always something hypnotic about watching bacteria multiply. So for my implementation, instead of a randomness, the evolution follows the rules of Conway's Game of Life.
For the uninitiated, cellular automata, is like a simulation of simple life forms. You have rules for growth, survival and decay. Conway's Game of Life is a form of cellular automata based on four simple rules:
  1. Any live cell with less than two live neighbours dies (as if by under-population).
  2. Any live cell with more than three live neighbours dies (as if by over-population).
  3. Any dead cell with exactly three live neighbours becomes a live cell (as if by reproduction).
  4. Any live cell with two or three neighbours lives on with no change in state.
You can find the code here: Game of Life Wallpaper. Its a simple python scrpt that takes an initial cell configuration stored as an lif 1life.06 file, generates image s based on other confgurations you can enter in the config.py file, and finally generates an XML that you can then set in Ubuntu as your wallpaper. The code is very rough, it is my first experiment with scipy, numpy or PIL so things may be done very inefficiently. I would love comments or suggestions. I would especially appreciate if anyone could tell me how to filter the image to make the colour gradiations look better.
A sample of a generated wallpaper:


I learnt quite a few interesting things working on this script. Most surprising was the amount of time people have spent on this. There is a wiki, which boasts a collection of about 600+ interesting patterns. There are about 6 file formats used to save cell configurations. People have written implementations in java, javascript, HTML5, and probably any other language you can write code in, I think its been implemented.

Notes:
The code for the Game of Life implementation was taken from here.