Project: Creating Visual Art with Genetic Algorithms Part 1
After seeing this collection of geometric designs, I remembered something that I was going to do. Genetic art, or rather evolving pieces of art.
The idea came to me when I was looking into what AI could be used to replicate. Something like creativity. I’m quite into geometric art, like the ones in the link above, so I wondered if I could replicate that using genetic algorithms.
I started out with a plan:
Initiate population (create drawings, that each contained 50 triangles of random vertices, colours, and transparencies).
Calculate the fitness of each drawing by testing how much it matched an original picture, pixel-per-pixel.
Mate the ones that are most fit.
Mutate the children.
Repeat.
This was the target drawing:
It took me a whole day to test and debug, and one of the major problems I encountered was that the fitness function was inefficient. I looked online for a bit of info and adapted mine so that it would only change one triangle per mutation and to not use cross-overs.
During the day, I also actually learnt a lot of Python and things you can do with the Pygame library.
For example:
To create transparent triangles in Pygame, you actually need to create another surface and blitz that surface onto the main surface.
You can also take a screenshot of the Pygame surface like so:
Anyway, the code takes forever to run. I wish I had more processing power or one of Google’s supercomputers (drool…. :o ) I’ll post an update showing the progress and what the result looks like. It’ll take a while, and I may have to leave the computer on overnight.