Skip to content

ckolin/pop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pop

Genetic algorithm to approximate a target image using semi-transparent rectangles.

Inspired by this blog post and this book.

Usage

go run pop.go -i "input.jpg"

How it works

  1. Generate a number of DNA elements with randomly sized and colored rectangles.
  2. Repeat the following:
    1. Calculate a fitness value for every element by comparing it to the target image.
    2. Repeat the following until a new population of the same size is created:
      1. Select two elements while favoring elements with high fitness value.
      2. Combine the two elements into a new DNA element.
      3. Randomly mutate the newly created DNA.

Example

After waiting for a good ten minutes we get something that vaguely resembles the Mona Lisa:

Mona Lisa not Mona Lisa

On the other hand, it can replicate a red square quite easily:

red square red square

And it gets pretty close to the Windows XP wallpaper as well:

Windows XP wallpaper almost Windows XP wallpaper

About

genetic drawing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages