Something like Sleep function
in
Programming Questions
•
7 months ago
Hello everyone!
I started to use processing few days ago,for exercise i tried to make a little program that display a traffic lights in off mode with a button and than when you press the button the lights start the classic traffic lights sequence.
To make the sequence in C language i can use the Sleep() function to freeze the program for few second when i want, in processing i didn't find anything like the sleep function so i tried to do something whit the millis function, this is the code:
When i run the program, the lights comes on together and it seems that the program don't follow the order of instruction, how i can fix this?
Sorry for my poor english and thank you!
I started to use processing few days ago,for exercise i tried to make a little program that display a traffic lights in off mode with a button and than when you press the button the lights start the classic traffic lights sequence.
To make the sequence in C language i can use the Sleep() function to freeze the program for few second when i want, in processing i didn't find anything like the sleep function so i tried to do something whit the millis function, this is the code:
- void setup() {
size(640, 480);
smooth();
fill(#CCCECC);
rect(210, 240, 220, 40);
fill(#090A09);
rect(295, 3, 50, 155);
textSize(20);
text("Start", 295, 250, 220, 40);
}
void draw() {
int stoptime;
if(mousePressed)
if (mouseButton == LEFT)
if ((mouseX > 210) && (mouseX < 430) &&
(mouseY > 240) && (mouseY < 280)) {
fill(#1AF507);
ellipse(320,135, 40, 40);
stoptime=millis()+1000;
while(stoptime>millis())
{
} - stoptime=millis()+1000;
while(stoptime>millis())
{
fill(#F5DA07);
ellipse(320,80, 40, 40);
}
fill(#F5DA07);
ellipse(320,80, 40, 40);
fill(#F50707);
ellipse(320,25, 40, 40);
}
}
When i run the program, the lights comes on together and it seems that the program don't follow the order of instruction, how i can fix this?
Sorry for my poor english and thank you!
1