evolutional algorithm for image rendering, c# faster then processing ?
in
Programming Questions
•
1 month ago
Hi,
I am working on a project inspired by EvoLisa [
http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/
], its a algorithm which takes an image and tries to recreate that image with semitransparent polygons. it calculates the difference to the orginal image (by mutating a clone of that image), and evolves to the best fit (selection).
I was looking at the original code and recreated the project in processing (2.0.3).
Idea:
We start with one polygon, we clone that drawing an mutate it, if the new drawing fits better we take it and clone that one and mutate it, if not, we stick with the old one.
A mutation moves, deletes, or adds points/polygons.
Every drawing (called "dnaDrawing") consists of a list of polygons (a list of random points). When i am drawing the polygons on the canvas i create a PGraphic, and "draw" my dnaDrawing on that PGraphic.
It seems that my implementation reaches about ~40% of the speed of the c# implementation.
My question is: is processing not at fast as c# ? Or is my rendering-method very slow ?
public static class Render {
public static void render (DnaDrawing drawing, PGraphics g) {
g.beginDraw();
g.background(0); //black
for (DnaPolygon polygon: drawing.polygons) {
Render(polygon, g);
}
g.endDraw();
}
public static void Render(DnaPolygon polygon, PGraphics g) {
color c = getBrushColor(polygon.brush);
g.fill(c);
g.noStroke();
g.beginShape();
for (DnaPoint p: polygon.points) {
g.vertex(p.x, p.y);
}
g.endShape(CLOSE);
}
private static color getBrushColor(DnaBrush b) {
color c = (b.alpha << 24) | (b.red << 16) | (b.green << 8) | b.blue;
return c;
}
}
thanks
1