metaphorz
Junior Member
Offline
Posts: 53
Re: Why is this so slow?
Reply #9 - May 9th , 2005, 10:04pm
Just as a followup, I put in some code that prints frame rate per second, and compared V69 with V89. a specific framerate() was set to 20. I am getting roughly 13fps on V69. For V89, here are some average rates: (1) default: 3.8 (2) P3D: 2.4 (3) OpenGL: 1.3 Framerate was set to specific values, and this didn't change anything substantially. I settled on 20. Here is the code (pick a .jpg image that you have to test it): import processing.opengl.*; // Pixel Swarm // Jon Danao // 2005.05.05 // www.danao.org // fps test float fps; int last_time,elapsed_time; // init values PImage img; int dim = 300; Pixel[] pixel = new Pixel[10000]; int pixelSize = 7; color pixelColor; int pixelCount = 0; void setup(){ size(dim,dim); framerate(20); last_time = 0; background(255); noStroke(); ellipseMode(CENTER_RADIUS); loadPixelData(); } void loadPixelData(){ img = loadImage("water.jpg"); image(img,0,0); for(int i=0; i<dim; i+=3){ for(int j=0; j<dim; j+=3){ pixelColor = get(i,j); if(pixelColor != color(255,255,255)){ pixel[pixelCount] = new Pixel(i,j,pixelColor); pixelCount++; } } } println(pixelCount); } class Pixel{ float x0,y0; float x1,y1; float xd,yd; float xs,ys; boolean exceeds = true; color c; Pixel(float i, float j, color pixelColor){ x0 = i; y0 = j; c = pixelColor; x1 = x0; y1 = y0; } void move(){ if(exceeds){ xd = random(-15,15) + x0; yd = random(-15,15) + y0; xs = (xd - x1) * 0.09; ys = (yd - y1) * 0.09; exceeds = false; } x1 += xs; y1 += ys; fill(c); ellipse(x1,y1,pixelSize,pixelSize); if(x1 > xd || y1 > yd){ exceeds = true; } } } void draw(){ elapsed_time = millis(); fps = 1000.0/(float) (elapsed_time - last_time); last_time = elapsed_time; println(fps); background(255); // for (int i=0;i<2;i++) { for(int i=0; i<pixelCount; i++){ pixel[i].move(); } }