This is a fast-ish java hill-climber that can approximate images with triangles!
Inspired by this video authored by the awesome Two Minute Papers
I welcome all pull requests: new image examples, typos, bug-fixes, functionality, layout, GUI or typo corrections will for sure be accepted! :)
Here's some cool results this program can produce.
I worked hard on optimising the image comparator, so it should work pretty fast (160 iterations/s at 50 triangles), but there's stil a large handicap:
// Population.java, v1.4.4
buffer = deepCopy(members); // < Copies the whole population array each time iterating
buffer[MathUtil.random(buffer.length)].mutate(); // < Fine
g.setColor(Color.WHITE);
g.fillRect(0, 0, Polygonizer.WIDTH, Polygonizer.HEIGHT); // < Clear background,
for (Polygon p : buffer) { // < Very, very bad! The speed of java graphics just isn't enough.
g.setColor(p.color); // < Simply removing this line triples the speed
g.fillPolygon(new int[] {(int) p.p1.x, (int) p.p2.x, (int) p.p3.x}, new int[] {(int) p.p1.y, (int) p.p2.y, (int) p.p3.y}, 3); // < Sloooooow
}
I have no idea what to do here, since multithreading is not an option with the Graphics api. Hope i or somebody else will figure it out in the future.