Git Product home page Git Product logo

pop's Introduction

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

pop's People

Contributors

ckolin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.