java - stop and restart flashing colors in processing -
i have following code flashes colors red , white. want make change i'm not sure how do. flashing 2 colors stopped 3 seconds , begins again.
float delay = 1; // 1 frame void setup() { size(200, 200); } void draw() { background(96); fill(255); if(framecount%(2*delay)<delay) fill(255, 0, 0); rect(20, 20, 100, 100); }
method 1
as guy hat suggested, draw rectangle when framecount%360 < 180
method 2
use timer:
float delay = 1; // 1 frame long n; void setup() { size(200, 200); n = millis(); } void draw() { background(96); fill(255); if (framecount%(2*delay)<delay) { fill(255, 0, 0); } if (millis() - n < 3000) // if 3 seconds haven't yet passed, show rectangle { rect(20, 20, 100, 100); } else if (millis() - n > 6000) // if 6 seconds have passed, reset timer { n = millis(); } }
Comments
Post a Comment