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 › Help with this clock
Page Index Toggle Pages: 1
Help with this clock (Read 1089 times)
Help with this clock
May 9th, 2010, 2:01pm
 
I made a simple clock program. Left column displays hours, the middle column, the seconds and the right one, the minutes. I've a problem whith this program. I can not make the ellipses of the hours, minutes, seconds, and the lines disappear every second, minute or hour that passes.

Can anyone help me?



Code:
float ysegundos,yhoras,yminutos;
void setup () {
size (350,700);
background (0);
for (int i=0;i<=24;i++) {
fill (#00039B);
rect (65,yhoras,8,5);
yhoras=yhoras+30;
}
for (int i=0;i<=60;i++) {
fill (#00039B);
rect (168,ysegundos,9,3);
ysegundos=ysegundos+11.5;
}
for (int i=0;i<=60;i++) {
fill (#00039B);
rect (270,yminutos,8,5);
yminutos=yminutos+11.5;
}
}
void draw (){
  fill (255);
  ellipse (162,second()*11.72,7,12);
  ellipse (184,second()*11.72,7,12);
  stroke(255);
  line (1,350,59,hour()*26.17);
  line (80,hour()*26.17,161,second()*11.72);
  line(184,second()*11.72,263,minute()*11.8);
  ellipse (263,minute()*11.8,7,12);
  ellipse (286,minute()*11.8,7,12);
  line (350,350,286,minute()*11.8);        
  ellipse (80,hour()*26.17,7,12);
  ellipse (59,hour()*26.17,7,12);
}


Thank you in advance.
Re: Help with this clock
Reply #1 - May 9th, 2010, 3:01pm
 
add   background(0); right after draw() to erase your screen with every frame. you have to move your grid  draw though.
Re: Help with this clock
Reply #2 - May 9th, 2010, 3:18pm
 
Cedric wrote on May 9th, 2010, 3:01pm:
add   background(0); right after draw() to erase your screen with every frame. you have to move your grid  draw though.


Thanks for you reply, but it doesn't work, because blue rectangles are deleted. I tried to put setup() iterations into draw(), but it doesn't work. I'm getting mad.

Thank you.

Code:
float ysegundos,yhoras,yminutos;
void setup () {
size (350,700);

}
void draw (){
background (0);

for (int i=0;i<=24;i++) {
fill (#00039B);
rect (65,yhoras,8,5);
yhoras=yhoras+30;
}
for (int i=0;i<=60;i++) {
fill (#00039B);
rect (168,ysegundos,9,3);
ysegundos=ysegundos+11.5;
}
for (int i=0;i<=60;i++) {
fill (#00039B);
rect (270,yminutos,8,5);
yminutos=yminutos+11.5;
}

fill (255);
ellipse (162,second()*11.72,7,12);
ellipse (184,second()*11.72,7,12);
stroke(255);
line (1,350,59,hour()*26.17);
line (80,hour()*26.17,161,second()*11.72);
line(184,second()*11.72,263,minute()*11.8);
ellipse (263,minute()*11.8,7,12);
ellipse (286,minute()*11.8,7,12);
line (350,350,286,minute()*11.8);
ellipse (80,hour()*26.17,7,12);
ellipse (59,hour()*26.17,7,12);
}

Re: Help with this clock
Reply #3 - May 9th, 2010, 3:57pm
 
your variables get bigger and bigger now as you dont reset them. one way would be to set them to 0 at the end of draw. but you actually dont need them at all.

just do it like that

 for(int i=0;i<=24;i++){
 rect (65,i*30,8,5);
 }
Re: Help with this clock
Reply #4 - May 9th, 2010, 3:58pm
 
Quote:
float ysegundos, yhoras, yminutos;
void setup(){
  size(350,700);
}

void draw(){
 background(0);
 fill(#00039B);
 noStroke();
 ysegundos = 0;
 yhoras = 0;
 yminutos = 0;
 for(int i=0;i<=24;i++){
   rect(65,yhoras,8,5);
   yhoras=yhoras+30;
 }
 for(int i=0;i<=60;i++){
   rect(168,ysegundos,9,3);
   ysegundos=ysegundos+11.5;
 }
 for(int i=0;i<=60;i++){
   rect(270,yminutos,8,5);
   yminutos=yminutos+11.5;
 }
 fill(255);
 ellipse (162,second()*11.72,7,12);
 ellipse (184,second()*11.72,7,12);
 stroke(255);
 line (1,350,59,hour()*26.17);
 line (80,hour()*26.17,161,second()*11.72);
 line(184,second()*11.72,263,minute()*11.8);
 ellipse (263,minute()*11.8,7,12);
 ellipse (286,minute()*11.8,7,12);
 line (350,350,286,minute()*11.8);        
 ellipse (80,hour()*26.17,7,12);
 ellipse (59,hour()*26.17,7,12);




You never reset the values of yhoras, ysegundos, or yminutos! Or, as Cedric suggested (he's quick!), use the looping variables themselves to determine positions.
Re: Help with this clock
Reply #5 - May 9th, 2010, 4:07pm
 
OMG What stupid mistake.

Thank you so much. I really appreciate it.
Page Index Toggle Pages: 1