i'm trying to apply voronoi tessellation on android, but the performance is too slow. it takes about 4 seconds to generate it and after some points it takes even more.
i wonder if the problem is the device or the algorithm is too long ..... or both?!
the device is HTC desireHD (cpu
1 GHz)
i tried to simplify the code as possible as i could
- float[] px = new float[0];
- float[] py = new float[0];
- float[] distance = new float[0];
- void setup()
- {
- size(800,480);
- orientation(LANDSCAPE);
- rectMode(CENTER);
- }
- void draw()
- {
- //rendering points as rectangles
- for(int i=0;i<px.length;i++)
- rect(px[i],py[i],10,10);
- }
- void mousePressed()
- {
- //add new point
- px = append(px,mouseX);
- py = append(py,mouseY);
- distance = append(distance,0);
- if(distance.length<2) return;
- for(int y=0;y<height;y++)
- for(int x=0;x<width;x++){
- //calculate the distance between the pixel and each point
- for(int i=0;i<px.length;i++)
- distance[i] = dist(x,y,px[i],py[i]);
- sortDistance();
- if(abs(distance[0]-distance[1])>5) set(x,y,color(0));
- else set(x,y,color(255));
- }
- }
- void sortDistance()
- {
- for(int i=0;i<px.length-1;i++)
- for(int j=i;j<px.length;j++)
- if(distance[i]>distance[j]){
- float d = distance[i];
- distance[i] = distance[j];
- distance[j] = d;
- }
- }
1