GeneticDrawing is a programme which uses a genetic/hill-climbing algorithm to draw a continually evolving copy of a source image, using a set number of polygons containing 3 or more points.
The process is as follows :
-
Setup a random DNA string (application start).
-
Copy the current DNA sequence and mutate it slightly.
-
Use the new DNA to render polygons onto a canvas.
-
Compare the canvas to the source image.
-
If the new painting looks more like the source image than the previous painting did, then overwrite the current DNA with the new DNA.
-
repeat from 1.
==============
The core classes are:
-
GeneticAlgo.java, which contains the method which preforms the above steps.
-
DNAString.java, which encapsulates a "solution". i.e a number of 'genes'
-
Gene.java, a gene encapsulates a polygon in the following format: Red Green Blue Alpha Xcoordinates... Ycoordinates..
-
FitnessCalculator.java, the fitness calculator gives a fitness rating, based on how simillar an image is to the calculators source image.
==============
Screenshots:
The app: https://oi57.tinypic.com/a0xobk.jpg
Firefox logo (50 polygons, 6 points) after ~300k candidate solutions: https://oi62.tinypic.com/2djuyhd.jpg
Mona Lisa (50 polygons, 3 points) after ~50k candidate solutions: https://oi58.tinypic.com/nq1mwz.jpg
==============
There is an option to export an SVG of the generated drawing File -> Export. You can change the number of polygons, points in the polygons, and the initial color of the DNA under Settings.
This programme is an implementation of Roger Alsings original idea: https://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/