Reputation: 87
I'm working on a small sketch in processing where I am making a "clock" using the time functions and drawing ellipses across the canvas based on milliseconds, seconds and minutes. I'm using a for loop to draw all of the ellipses and each for loop is inside its own method. I'm calling each of these methods in the draw function. However for some reason only the first method that is called is being drawn, when ideally I would like to have them all being visibly rendered.
//setup program
void setup() {
size(800, 600);
frameRate(30);
background(#eeeeee);
smooth();
}
void draw(){
milliParticles();
secParticles();
minParticles();
}
//time based particles
void milliParticles(){
for(int i = int(millis()); i >= 0; i++) {
ellipse(random(800), random(600), 5, 5 );
fill(255);
}
}
void secParticles() {
for(int i = int(second()); i >= 0; i++) {
fill(0);
ellipse(random(800), random(600), 10, 10 );
}
}
void minParticles(){
for(int i = int(minute()); i >= 0; i++) {
fill(50);
ellipse(random(800), random(600), 20, 20 );
}
}
Upvotes: 0
Views: 168
Reputation: 2336
Your first method is the only one being executed because the condition which must be false in order for your for loop to stop is always true (i will always be >= 0 if you add 1 to it each time you loop).
I think you want to modify your for loops like so:
for(int i = int(second()); i >= 0; i--) {
This way, i will initially be 0-59, and will decrease until it is -1, at which point i >= 0 will be false. Execution will then exit the for loop and pass to the next method.
I think this was your original intent, unless you wanted each method to run simultaneously and indefinitely (in which case you should use threads).
Upvotes: 2