A genetic algorithm creates a population of individuals and then uses a "natural selection" mechanism to improve the population fitness with respect to a specific criteria.
At every new generation:
- The worst performing individuals are replaced by the children of the best performing individuals
- Every new individual has a random chance to be mutated. This helps finding new solutions.
In this case, each picture is an individual (a possible copy of the sample image) and the fitness is measured as the number of pixels that are equal to the corresponding ones in the sample image.
You can play with the parameters and see how the outcome changes.
If you're interested in the code, you can find it on my Github repository
Warning! High values of population size and refresh rate may cause a strong slowdown!