I took some time off from particles this week after a conversation in the pub started me thinking about genetic algorithms. Genetic algorithms are a technique by which a randomised solution to a problem is created and a mutated version (or versions) is (or are) spawned. The original solution and the mutated version are compared for their fitness against a solution and the fitter lives on the spawn another mutated version.

In my experiment, the solutions are random arrays of translucent triangles and the fitness function compares those random arrays against a character of text. The idea being after several generations of mutation and selection through the fitness function, the random array would start to resemble the target character .

Here's the work-in-progress Flex application (right click for source). I've added a UI that allows the user to select the target text, tweak some parameters and run the simulation.

This was primarily an intellectual exercise, but I can the see real applications:
  • Creating properly, randomised deconstructed type: most deconstructed type is based on a fixed font and each instance of each letter is identical. To me, this just looks odd and each instance of the same character should look different.
  • As a source of still images for interesting typographic transitions. It would be interesting to store each new successful (i.e. fitter) mutation and animate them from their original fully randomised state to their more evolved state.
The fitness function lives in the GeneticTypeWidget class. In a nutshell, it examines every pixel in the parent 'dna' and the mutated 'dna' against the target text. Since I'm only using black and white, I've selected a single, arbitrary colour channel for comparison to speed things up. As Flex loops over each pixel, it adds the the pixel difference to a fitness variable and at the end of the loop, the 'dna' whose fitness variable is less lives on for another generation.

On my machine, it can take a good few minutes before the images start to resemble the target text. Sans serif, simple characters tend to work best and as the simulation runs, the mutations become less and less likely to be fitter than their parent, so the successful mutations become less frequent.

The application lives here and the source code here.

[Note: the initial random triangle code has been tweaked so they are smaller triangles and the effect is a lot nicer]
2

View comments

About Me
About Me
Labels
Labels
Blog Archive
Loading