## Genetic ArtKyrre Glette and I wrote a simple image generator using genetic programming for an artificial intelligence course. Here are some of the images it made.
The names are also random. ## amal## slimsy## benedictor## deplorencher## habi## avager## centranscription## polytica## enide## conds## nicky## archfork## sheel## mement## emorian## cation## fruisit## messions## conded## crystalgic## tavnit## lipse## gol## courn## How it worksAn image is generated by a mathematical expression that calculates a value for each pixel given its (x,y) coordinates. For instance, the simple formula x*y looks like this: The coordinates range from -1 to 1. The bottom right corner, for instance, has coordinates (1,1), and thus gets the color 1*1 = 1, or white. Here's a typical expression:
The expression trees for the images at the top range from 40 to 1000 operations. These all need to be evaluated from scratch for each individual pixel. To make the system fast enough for us to play with it in near real time, the expressions were compiled to x87 machine code on the fly. The functions were all generated by randomly mutating graph nodes using a few simple mutations: Individual nodes in the expression tree would be replaced by similar nodes (often) or by new subtrees (more rarely). Also, two images could be cross-bred, merging the 'genes' of two good-looking images to generate offspring, hopefully combining the valuable parts of each parent image. By adding looping constructs to the 'expression language', we were able to make the system invent fractal shapes. Since the images are built from mathematical expressions and not pixels, they can be generated at any resolution. Rendering 50-megapixel images suitable for print is a matter of toggling a switch on the command line. ## AnimationThere are many numerical constants in the expressions. The overall structure and feel of an image comes from its structure, but the actual incarnation is determined by those constants. The image is only a single point in the 100-or-so-dimensional space of possible parameters. I hacked together a small script that would plot an ellipse through the many-dimensional space intersecting the point defining the original image. Here are some animations:
An interesting thing to do with this would be to generate the parameters in real time based on some external data source (from, say, running music through a frequency analyzer). ## Comments |