Loading...
Logo
Processing Forum
Dear friends, 

I am a starter in Processing. I hope you can help me with the following problem that I have... Thanks!

I would like to show the flickering (1 frame/sec) of the following two images generated using Processing.
How to do that?

I was able to generate the two images one by one using Processing. But how to put them together to show the two images alternating for 20 seconds? Can this be done in Processing Environment? Or I have to use Quicktime or other animation software to generate the pattern reversal?

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

size(480, 480);
background(0);
smooth();
noStroke();


for (int y = 0; y <= height; y += 80) {
  for (int x = 0; x <= width; x += 80) {
    fill(255, 255);
    rect (x, y, 40, 40);
  }
}

for (int y = 40; y <= height; y += 80) {
  for (int x = 40; x <= width; x += 80) {
    fill(255, 255);
    rect (x, y, 40, 40);
  }
}






size(480, 480);
background(255);
smooth();
noStroke();

for (int y = 0; y <= height; y += 80) {
  for (int x = 0; x <= width; x += 80) {
    fill(0);
    rect (x, y, 40, 40);
  }
}

for (int y = 40; y <= height; y += 80) {
  for (int x = 40; x <= width; x += 80) {
    fill(0);
    rect (x, y, 40, 40);
  }
}




Replies(5)

Copy code
  1. boolean b;
  2. int time, start, pause;

  3. void setup() {
  4.   size(480, 480);
  5.   b = false;
  6.   pause = 1000;
  7.   start = millis();
  8.   time = start + pause;
  9.   smooth();
  10.   noStroke();
  11. }

  12. void draw() {
  13.   background(b?0:255);
  14.   fill(b?255:0);
  15.   for (int y = 0; y <= height; y += 80) {
  16.     for (int x = 0; x <= width; x += 80) {

  17.       rect (x, y, 40, 40);
  18.     }
  19.   }
  20.   for (int y = 40; y <= height; y += 80) {
  21.     for (int x = 40; x <= width; x += 80) {
  22.       rect (x, y, 40, 40);
  23.     }
  24.   }
  25.   if( millis() > time ){
  26.     b = !b;
  27.     time = millis() + pause;
  28.   }
  29.   if( millis() > start + 20000 ){
  30.     background(0);
  31.     fill(255);
  32.     text( "Twenty seconds has past. I don't know what you want to happen now.", 20, 20 );
  33.   }
  34. }
It worked! Thank you so much tfguy44!

If I want to make the pattern reversal stop after 5 minutes. How to do that?
20 seconds is 20000 milliseconds.
5 minutes is 300 seconds, or 300000 milliseconds.
The test for "Has 20 seconds past?" is on line #32.