Skip to content

Code to go along with the post about Genetic Algorithms to re-draw art

License

Notifications You must be signed in to change notification settings

4dcu-be/Genetic-Art-Algorithm

Repository files navigation

Genetic Art Algorithm

This is the code that goes with the blog post here. A genetic algorithm is used to morph 150 random triangles into something resembling Van Gogh's The Starry Night. You can see the progression from the 1 generation to generation 4500 below.

Evolving 150 triangles into a famous painting

The final result after 5000 generations you can check out below

Final result after 5000 generations

Note that running this code will take a long time, all 5000 generations took about 10 hours on my machine.

Running the code

To run the code in this repository clone it, set up a virtual environment and install the required packages from requirements.txt

git clone https://github.com/4dcu-be/Genetic-Art-Algorithm
cd Genetic-Art-Algorithm
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Next you can run evolve.py and evolve_simple.py using

python evolve.py
# or
python evolve_simple.py

The paths to the target image and output directory are hard-coded, but can easily be changed. the lines are in the main routine.

    target_image_path = "./img/starry_night_half.jpg"
    checkpoint_path = "./starry_night/"

About

Code to go along with the post about Genetic Algorithms to re-draw art

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages