We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › frameRate !!!  
Page Index Toggle Pages: 1
frameRate !!!   (Read 1102 times)
frameRate !!!  
Apr 13th, 2007, 1:45am
 
hi,
does someone knows why it´s not posible for me to have a better frameRate as 20~23. It doesn´t makes also any difference if I write frameRate(60); in my code or if I set a bigger max available memory like 1024MB in teh Processing menu.
I´m charging only one jpeg image "136kb, 96x1056" 3 times per Loop in a white Background. I hope this info helps to find an  answer.

Thanks!
Re: frameRate !!!  
Reply #1 - Apr 13th, 2007, 6:40am
 
this normally happens because your code is to slow. post it here and we can have a look where to optimize.

btw. frameRate() will try to set an upper limit, read it as "max frame rate".

F
Re: frameRate !!!  
Reply #2 - Apr 13th, 2007, 7:44pm
 
ok thanks! so, hier is the code
I reduced the size() in a Half, and it helped a lot, although what I would realy like is to run a widescreen size Program.
The other thing was that even when it runed quite well it makes every now and then abruptiontions like little pauses, and then continues perfektly like before. I think it migth me a problem with my processor, and I don´t know hao to give priority to my applet in the processor while it´s running.

PImage b;
int num = 3;
Waltzen[] waltzen = new Waltzen[num];
float [] vel= new float [num];


void setup()
{
 b = loadImage("wKopie.jpg");
 size(400,300);
 smooth();
 frameRate(50);
 waltzen[0]= new Waltzen(50,-762,b);
 waltzen[1]= new Waltzen(150,-762,b);
 waltzen[2]= new Waltzen(250,-762,b);
}


void draw()
{  
 background(255);
 ypos();
 if(mousePressed && (waltzen[0].vel<=85)){
   for(int i=0; i<=(num-1);i++){
     waltzen[i].vel+=random(0.5,1.1);  
   }
 }
 for(int i=0; i<=(num-1);i++){  
   waltzen[i].draw();
   println(waltzen[i].ypos+" FR "+frameRate);                      
 }  
}

class Waltzen{
 float xpos, ypos, vel, acc;
 PImage img;
//initialize the Object and overload an image a the position
//waltzen[i]=new Waltzen(x,y,image)
 Waltzen(float i_xpos, float i_ypos, PImage i_img){
  xpos=i_xpos;
  ypos=i_ypos;
  img=i_img;
 }

//call waltzen[i].draw() will draw the image to the screen
 void draw(){
   
   image(img, xpos, ypos);
 }
}
boolean canPlay(){
 if((waltzen[0].vel<=0) && (waltzen[1].vel<=0) && (waltzen[2].vel<=0)){
   return true;
 }
 else {return false;}
}
//The picture it´s diveded in 6 parts, and should apper //without interruption, it should see has if it loops,
//this is a representation of the picture: 0000.11 the real //picture its represented by the 0000 and the 11 its only a //repetition of the first half of the picture (00)00.11

void ypos(){
 for(int i=0; i<=num-1;i++){
   waltzen[i].ypos+= waltzen[i].vel;  
   
   if(waltzen[i].ypos>=5){
     waltzen[i].ypos=-762;
     //5 its the hight where the picture muss go up again.
   }
 }
}

Once again thanks a lot!

Re: frameRate !!!  
Reply #3 - Apr 14th, 2007, 10:37pm
 
OK, Here I´m once again, I wrote the program in a completely new structure. Lets say I brought order in it! It still does´t run as wished, I hope you can take a Look around. I would apreciate it a lot. And believe me, once I reach a better level I´ll be also helping the needed onces remembering times like this one Wink

thats the class Walzen

class Walzen{
 // screen var
 float xpos, ypos, tempypos, rest_posy, v0, vel, acc, anker_ypos;
 PImage img;
 boolean over, velMax, velMin, fest, pressed, released;

 // physical var
 float mass, k, damp, accel, force;

 int me;

 Walzen (float x, float y, PImage i, float m, float d, float k, int id ){
   xpos=  x;
   ypos=  y;
   img=   i;
   mass=  m;
   k=     k;
   damp=  d;
   me=   id;
 }

 void setv0(){
   v0= random(0.5, 1.5);
 }

 void setVel(){
   if(!over && !velMax  && !velMin){
     vel=v0+acc;
   }
   if(vel>= 90){
     velMax= true;
   }
   else{
     velMax =false;
   }
   if(vel<= 1.4){
     velMin= true;
   }
   else{
     velMin=false;
   }
 }

 void setAcc(){
   if(over && otherOver()){
     acc=   random(1, 1.25);
   }
   else{
     if(velMax && otherVelmax() && released){
       acc= random(-0.5,-1);
     }
   }
 }

 boolean otherVelmax(){
   for(int i=0; i<num; i++){
     if(i!= me){
       if( walzen[i].velMax){
         return true;
       }
     }
   }
   return false;
 }

 boolean otherOver(){
   for(int i=0; i<num; i++){
     if(i!= me){
       if( walzen[i].over){
         return true;
       }
     }
   }
   return false;
 }

 float ankerPoint(){
   return ((ypos/yU)%100)*yU;
 }

 void setYpos(){
   if(!velMin && !over){
     ypos+= vel;
   }
   if(velMin && !over)
   {
     tempypos=ypos;
     rest_posy = ankerPoint();  

     force = -k * (tempypos - rest_posy);  // f=-ky
     accel = force / mass;             // Set the acceleration, f=ma == a=f/m
     vel = damp * (vel + accel);     // Set the velocity
     tempypos = tempypos + vel;               // Updated position
     ypos= tempypos;

     if( vel==0 ) {
       over = true;
     }
     else {
       over = false;
     }
   }
 }
 void update(){
   if(pressed){
     if(over){
       setv0();
     }
     setAcc();
     setVel();
     setYpos();
   }
 }
 void draw(){
   image(img, xpos, ypos);
 }
}

//and here is the Principal program

PImage b;
int num = 3;
int N=11;  //number of objects in the picture
float yU;
Walzen[] walzen = new Walzen[num];
float [] vel= new float [num];
boolean feder;

void setup()
{
 b = loadImage("wKopie.jpg");
 size(400,300);
 smooth();
 frameRate(30);
 yU= b.height/N;
 translate(0, (-762-yU));
 walzen[0]= new Walzen(50, 5, b, 8.0, 0.98, 0.1, 0);
 walzen[1]= new Walzen(150,5, b, 8.0, 0.98, 0.1, 1);
 walzen[2]= new Walzen(250,5, b, 8.0, 0.98, 0.1, 2);
 
}


void draw()
{  
 background(#FFFFFF);
 
 for(int i=0; i<=(num-1);i++){  
   walzen[i].update();
   walzen[i].draw();
   println(walzen[i].ypos+" FR "+frameRate+"yU"+ yU);
 }  
}

void mousePressed()
{
 for(int i=0; i<num; i++) {
   walzen[i].pressed=true;
 }
}

void mouseReleased()
{
 for(int i=0; i<num; i++) {
   walzen[i].released=true;
 }
}

Thanks in forward!
Gustavo
Re: frameRate !!!  
Reply #4 - Apr 15th, 2007, 1:23pm
 
Hi the first think I've found is that your acc is never been set to any value, cause in the function setAcc no expression will be true. All the variables (over, otherOver(), velMax && otherVelmax()) are never set to true, cause acc is never set.

Da beißt sich die Katze in den Schwanz Smiley
Re: frameRate !!!  
Reply #5 - Apr 17th, 2007, 2:31am
 
Ok, Thanks once again, it´s good to feel helped! I´m now checking & changing the details you metioned, the code it´s allmost there! it allmost runs as I wish! Wink
Ass soon as I´m finished  (and I think i´ll be tomorrow), I´ll post it here! in order to share the achievements!

Ich hasse Katze! Wink
Eskimo, wo kommst du her?
Re: frameRate !!!  
Reply #6 - Apr 17th, 2007, 12:19pm
 
aus Berlin
Re: frameRate !!!  
Reply #7 - Jun 13th, 2007, 12:04am
 
General optimization tip: if you're having frame rate problems, they will only become worse if you start printing out the frame rate each frame.  I usually set up something to average the frame rate over the past 30 or so frames and only print it out once a second or so to get a better estimate (the single-frame frame rate is a bit volatile).  I'd post code, but I don't have any that's not attached to big sketches...basically, just have an integer counter variable, and increment it each frame, only printing if counter%30==0.  This will tend to give you a slightly better sense of your code's speed, though the amount that print statements slow down the code differs from computer to computer.
Page Index Toggle Pages: 1