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 & HelpSyntax Questions › how to reset after ### frames (in a loop)
Page Index Toggle Pages: 1
how to reset after ### frames (in a loop) (Read 581 times)
how to reset after ### frames (in a loop)
Apr 26th, 2010, 1:39pm
 
I would like to know how I can reset after 100 frames in a loop.
What I have written now doesn't repeat the act ... it comes only once white, after 100 frames, but I wish that it also resets after 200, 300, 400, ... frames. How do I do that?

Code:

float[][] a=new float[40][2];

int  nbrPasses;

void setup(){
 size(900,600);
 noStroke();
 fill(0,10);
 background(255,0);


}

void draw(){
 a[0][0]=mouseX;
 a[0][1]=mouseY;
 for(int i=1;i<40;i++){
   stroke(99,0,i*3,i*4);
   line(a[i][0],a[i][1],a[i][0]+=(a[i-1][0]-a[i][0])/i,a[i][1]+=(a[i-1][1]-a[i][1])/i);
 }

// IT CONCERNS THIS BIT:
  ++nbrPasses;
 if (nbrPasses == 100)
 {
   println("100");
   save("snapshot.png");
   fill(255);
   rect(0, 0, width, height);
}
}


Thanks for the help!
Re: how to reset after ### frames (in a loop)
Reply #1 - Apr 26th, 2010, 1:44pm
 
the obvious way is to set nbrPasses = 0 when it gets to 100 so that it just starts again.

or use the modulo operator in your test - (nbrPasses % 100) == 0
Re: how to reset after ### frames (in a loop)
Reply #2 - Apr 26th, 2010, 2:02pm
 
Note that frameCount variable is the same as your nbrPasses and is automatically incremented on each call of draw().
Page Index Toggle Pages: 1