Loading...
Logo
Processing Forum
I have this code. It generates a random 2D Greyscale Image. Works fine.

size(1920,1080);
int cols = width;
int rows = height;


int[][] myArray = new int[cols][rows];


for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
myArray[i][j] = int(random(255));
}
}


for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
stroke(myArray[i][j]);
point(i,j);
}
}

Now the thing i couldnt get my head around for a very long time is how i can make it:
Compute and Show Image for X seconds then, Compute and Show (an other) Image for X seconds (loop).
After start or key pressed.
In Fullscreen.

Help would be very very much appreciated. I just cant do it.

Cheers

Replies(2)

For demonstration purposes, I reduced the size of your sketch. You can re-adjust it if you need to. I assumes "X seconds" was actually "5 seconds"; you can adjust this value (defined as 5000 milliseconds) on line 20.

Copy code
  1. PImage myImage;
  2. int nextTime;
  3. void setup(){
  4.   size(200,200);//1920,1080);
  5.   myImage = new PImage( width, height );
  6.   newImage();
  7. }
  8. void draw(){
  9.   if( millis() > nextTime ){
  10.     newImage();
  11.   }
  12. }
  13. void newImage(){
  14.   for (int i = 0; i < width; i++) {
  15.     for (int j = 0; j < height; j++) {
  16.       stroke(color(random(255)));
  17.       point(i,j);
  18.     }
  19.   }
  20.   nextTime = millis() + 5000;
  21. }
  22. void keyPressed(){
  23.   newImage();
  24. }
thank you so much tfguy44
didnt know how to connect a draw() with the array =)

managed to fix the fullscreen part with a library upgrade:

  import fullscreen.*;
   
    FullScreen fs;
   
    PImage myImage;
    int nextTime;
    void setup(){
      size(1920,1080);//1920,1080);
      myImage = new PImage( width, height );
      newImage();
      fs = new FullScreen(this);
      fs.enter();
    }
    void draw(){
      if( millis() > nextTime ){
        newImage();
      }
    }
    void newImage(){
      for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
          stroke(color(random(255)));
          point(i,j);
        }
      }
      nextTime = millis() + 1000;
    }
    void keyPressed(){
      newImage();
    }