Using genetic algorithms to build images from layers of translucent polygons.
Inspired by this and also this.
Just learning Python! The code is here: https://github.com/darkFunction/PolygonPainter.
The old_painter
directory contains an non-breeding strategy in which a single entity or 'artist' is mutated according to a set of weightings, and un-mutated if the fitness is worse than it was before the change. This is similar to the Mona Lisa implementation linked above. We use an object heirarchy of shapes, points, and colours,and use the Command Pattern to encapsulate and optimise changes to these objects.
I found it to not work as well as I had hoped, and was blindly playing trial and error with the parameters to tweak the quality of the results. The program would quickly reached a local maxima, especially when given full freedom of range on the alpha channel.
For the new version I wanted to use a 'pure' genetic algorithm approach, so each artist is represented by a string of 'DNA', of the format:
numPolys, polyVertCount, R, G, B, A, x1, y1, x2, y2... R, G, B, A, x1, y1...
We initialise a population and run it through an evolution cycle as follows:
- The two fittest pass into the next generation unchanged
- The rest are bred together in pairs by splicing the DNA sequence to produce an offspring which is then mutated
- The pairs which are chosen to breed are randomly selected with a bias towards the fittest
New Improvements
- Mutations are either hard, medium, or soft, and we switch between these levels every 100 generations. Hard mutations are the changing of all of a single polygon's properties to new values. Medium changes a single parameter in the DNA string to a random value, and soft changes a single value by a small amount.
- Polygons are initialised around a point and with a limited size, to encourage regular shapes.
- DNA is spliced together polygon by polygon as opposed to value by value, since it makes more sense to treat polygons as atomics.
- Elitism is increased by discarding the bottom few from each generation.
You have my upvote : ) Implemented very similar algorithm out of curiosity years ago. Not a python coder myself, but like your code. Cheers!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks! I was very surprised how much better the pure GA approach was than the 'hill-climbing' method. It really works.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @darkfunction! You have received a personal award!
Happy Birthday - 1 Year
Click on the badge to view your own Board of Honor on SteemitBoard.
For more information about this award, click here
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @darkfunction! You have received a personal award!
2 Years on Steemit
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Semi Finals - Day 1
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @darkfunction! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit