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 › clock image won't restart
Page Index Toggle Pages: 1
clock image won't restart (Read 303 times)
clock image won't restart
Jan 20th, 2009, 10:25am
 
hi,
i'm making a clock using the noise() function.

i'm having trouble with having the separate images for the seconds, minutes, and hours loop back around. they are supposed to move from the left to the right of the screen, and start over when they have reached to right of the screen. so far, they just stop once they reach the end.

does anyone know how to fix this? do i need to put them in classes? any help would be REALLY great! thanks!



void setup(){
size(600, 200);
background(#CCCCBB);
}

void draw(){
 secdraw();
 mindraw();
 hourdraw();
}
 
//NOT RESTARTING!  
void secdraw(){  
 float s = map(second(), 0, 60, 0, 600);
 float v = 0.0;
 float inc = 0.1;
 for (int i = 0; i < s; i = i+4){
   fill(255);
   noStroke();
   noiseSeed(0);
   float n = noise(v) * 70.0; //noise() function is used to create smoother transitions thatn the #s returned by random  
   rect(i, 5 + n, 2, 10);
   v = v + inc;  
 }
}

void mindraw(){
 float m = map(minute(), 0, 60, 0, 600);
 float v = 0.0;
 float inc = 0.1;
 for (int j = 0; j < m; j = j+4){
   fill(255);
   noStroke();
   noiseSeed(0);
   float n = noise(v) * 70.0; //noise() function is used to create smoother transitions thatn the #s returned by random  
   rect(j, 20 + n, 2, 55);
   v = v + inc;
 }
}

void hourdraw(){
 float h = map(hour(), 0, 24, 0, 600);
 float v = 0.0;
 float inc = 0.1;
 for (int k = 0; k < h; k = k+4){
   fill(255);
   noStroke();
   noiseSeed(0);
   float n = noise(v) * 70.0; //noise() function is used to create smoother transitions thatn the #s returned by random  
   rect(k, 80 + n, 2, 85);
   v = v + inc;
 }
}
Re: clock image won't restart
Reply #1 - Jan 20th, 2009, 1:07pm
 
Classical problem: you need to put the background() call at the start of draw().
Re: clock image won't restart
Reply #2 - Jan 20th, 2009, 7:23pm
 
haha. thank you so much, PhiLho!
Page Index Toggle Pages: 1