# Genetic Art

I was experimenting with a lot of Genetic/Hill Climbing algorithms to generate Art. I started out by trying to approximate a Grayscale image with just lines of varying width and color intensity.

The genetic algorithm is roughly like this:

The first image after several geneartions..

I lost the original image I was trying to approximate.. but doesn’t that look like a deer? 🙄 I modified the algorithm several times to approximate my face. This is the original image..

FYI this is what I look like

First Attempt: Program too slow. Had to stop after 10 Hours.

Second Attempt: Rewrote the program to use Numpy arrays and Bezier Curves instead on just Lines. Also now in Technicolor!

Bugfixes & Third Attempt: Atleast it’s converging to something

But I didn’t look like this at all :/ . The problem here was that the fitness function was

$\sum_{pixel=1}^{NPIXELS} abs(original[pixel] - Generated[pixel])$

I tried squaring. squaring increases error distance. So fitter drawings would have a higher chance of being selected.

$\sum_{pixel=1}^{NPIXELS} (original[pixel] - Generated[pixel])^2$

and it worked (sort of. from an artistic point of view)!

I used this code to generate a lot of images, of different shapes.

My eventual plans were to create a bot which tweets these images. I even wrote a small program that gets a random Picassa image and bezierifies it. Unfortunately, someone else has already done it. And it’s much better than mine. But I learned a lot doing this project.

Written by Atul Vinayak on 01 October 2016