loper
Ex Member
saveImage and Framerate
Aug 5th , 2008, 12:19am
hi there! i guess my question has a pretty simple answer for most of you: I did a small program that create something similar to the rain, my final aim is to relate the movements of the drops with a music track. Since I'm not yet enough skilled to do an algorithm that does that for me, i created some kinds of interaction that let me act as "VJ". The problem is that if I add the saveImage function, the frame rate slow down too much, and i can't anymore interact in a fluent way. Any ideas? i post the code: class goccia{ float vy; float ay; float px, py; float kx; float oldx,oldy; float w,h; float d,dx; float ky = random (0,300); float kBounce,kkx,kSw; void update(){ vy+=ay; py+=vy; /* d = dist (mouseX,mouseY,px,py); dx = (mouseX-px); if (dx<0){ px+=pow((1/d)*100,4); } if(dx>0){ px-=pow((1/d)*100,4); } if(py > height-ky){ vy = -(vy/5); //py=height-50; kx = random (-5,5); //for (int i=0; i< 5; i++){ w = random(5,50); h = random(2,10); noFill(); stroke (0,20); ellipse (px,py,w,h); // } } */ if(py > height-10){ vy = -(vy/(1*kBounce)); // kx = random (-5,5); } if(vy <0){ kx = random (-5,5); } } void render(){ stroke (250); strokeWeight(1+kSw); line (px-kkx-kx,py,px+kkx+kx,py); line (px-kkx-kx,py+5,px+kkx+kx,py+5); } void init (){ oldy = py = 0; oldx = px = random (0,width); ay = random (0.3,0.9); kx=0; } } int nPioggia = 400; int frame; int kkx,kSw; goccia[] pioggia = new goccia [nPioggia]; void setup (){ size (1400,700); for (int i=0;i<nPioggia;i++){ pioggia[i] = new goccia(); } for (int i=0;i<nPioggia;i++){ pioggia[i].init(); } } void draw(){ if (frameCount % 1 == 0){ frame++; int indice = frame % nPioggia; pioggia[indice].init(); } fill(0, 0, 0,30); noStroke(); rect(0,0,width,height); for (int i=0; i<nPioggia;i++){ pioggia[i].update(); pioggia[i].render(); } //interazioni if (keyPressed==true){ //incrementa lunghezza linee if(key=='v'){ for (int i=0; i<nPioggia;i++){ pioggia[i].kkx+=2; } } if(key=='f'){ for (int i=0; i<nPioggia;i++){ pioggia[i].kkx=random(-1,20); pioggia[i].kSw=3; } } if(key=='p'){ for (int i=0; i<nPioggia;i++){ //if ((pioggia[i].py>300) && (pioggia[i].py<303)){ noStroke(); fill(255); rect(pioggia[i].px-10,pioggia[i].py-10,20,20); pioggia[i].kSw=0; //} } } if(key=='d'){ for (int i=0; i<nPioggia;i++){ pioggia[i].kBounce=random(1,2); if (pioggia[i].vy<=0){ pioggia[i].kSw=3; } } } } else{ for (int i=0; i<nPioggia;i++){ pioggia[i].kkx=5; pioggia[i].kSw=0; pioggia[i].kBounce=5; } } //smooth(); saveFrame("line-####.tif"); } void keyReleased() { if (keyCode == BACKSPACE) { for (int i=0; i<nPioggia;i++){ pioggia[i].init(); } } }