Skip to content

Fast java program that can approximate images with triangles

License

Notifications You must be signed in to change notification settings

jiftoo/EvoImage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EvoImage

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! :)


Contents:

  1. Examples
  2. Performance

Examples

Here's some cool results this program can produce.

  1. 60 vertices, 2 minutes

  2. 650 vertices, 1 hour


Performance

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.

About

Fast java program that can approximate images with triangles

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages