Skip to content

Rectilinear Randomized Composition

Composition of random rectangles with Processing.

A randomized composition maker that will create shapes of a random size, filled with a random shade of grey, and place them in a random spot within the display window. The fill() function is passed a random number between 0 and 255 to determine the shade of grey. A rectangle is then created with the rect() function, passing in random numbers from 0 to the display width and height to determine the size, and random locations within the display window.

void draw() {
      fill(random(255));
      int randomNumber = ceil(random(4));
      rect (random(displayWidth), random(displayHeight),
      random(displayWidth/randomNumber),
      random(displayHeight/randomNumber)); 
}

Randomized Composition

When the mouse is pressed the composition maker will stop temporarily and save the current composition. The noLoop() function in mousePressed() stops the application, then the Loop() function in mouseReleased() starts it again.

void mousePressed() {
      noLoop();
      saveFrame(timeStamp() + ".png");
}
void mouseReleased() {
      loop();
}

Each composition saved is named with the date and time, such as: 5-10-2016_21.23.59.png.

String timeStamp() {
      int d = day();    
      int m = month();  
      int y = year();   
      int s = second();  
      int n = minute(); 
      int h = hour();  
      
     return String.valueOf(m) + "-" + String.valueOf(d)+ "-" + 
     String.valueOf(y)+ "_" + String.valueOf(h) + "." + String.valueOf(n) 
     + "." + String.valueOf(s);
    }

Randomized Composition

Randomized Composition

Randomized Composition Code

void setup() {
      size(400, 400);
}

void draw() {
      fill(random(255));
      int randomNumber = ceil(random(4));
      rect (random(displayWidth), random(displayHeight),
      random(displayWidth/randomNumber),
      random(displayHeight/randomNumber)); 
}

void mousePressed() {
      noLoop();
      saveFrame(timeStamp() + ".png");
}

void mouseReleased() {
      loop();
}

String timeStamp() {
      int d = day();    
      int m = month();  
      int y = year();   
      int s = second(); 
      int n = minute(); 
      int h = hour();    
      
     return String.valueOf(m) + "-" + String.valueOf(d)+ "-" + 
     String.valueOf(y)+ "_" + String.valueOf(h) + "." + String.valueOf(n) 
     + "." + String.valueOf(s);
    }

These code snippets were written in 2008 but work with the current version of Processing (as of this post, v3).