Cubic Disarray by Georg Nees

We had to recreate the famous painting by Georg Nees in Javascript in the previous class. Though this one looked easy, it took more thinking and tweaking.

What we did in the class was to give the painting a bit a twist by writing the code to produce random color effect from the pallet we described, each time we clicked and hovered over a squares.

The code for that is written below:

float squareWidth = 0;
float margin = 10;
int squareNumX=12;
int squareNumY=24;
//Georg Nees Cubic Disarray
void setup() {
 size(320, 620);
 background(255);
 noFill();
 strokeWeight(0.5);
 stroke(0);
 frameRate(24);
 squareWidth = (width-margin * 2)/squareNumX;
 float randomness = 0;
 for (int j=0; j<squareNumY; j++) {
 for (int i=0; i<squareNumX; i++) {
int sign=1;
 if (random(0, 2)>1) {
 sign = -1;
 }
 float x =((width-margin*2) / squareNumX * i) + margin;
 float y =((height-margin*2) / squareNumY * j) + margin;
 pushMatrix();
 translate(x + sign*randomness, y);
 rotate(radians (randomness*sign) );
 rect(0, 0, squareWidth, squareWidth);
 popMatrix();
 randomness = randomness + random(0.075);
 }
 }
 //noLoop();
}
void draw() {
 float randomness = 0;
 for (int j=0; j<squareNumY; j++) {
 for (int i=0; i<squareNumX; i++) {
int sign=1;
 if (random(0, 2)>1) {
 sign = -1;
 }
 float x =((width-margin*2) / squareNumX * i) + margin;
 float y =((height-margin*2) / squareNumY * j) + margin;
 pushMatrix();
 translate(x + sign*randomness, y);
 rotate(radians (randomness*sign) );
 if (mouseX>x && mouseX < x+squareWidth
 && mouseY>y && mouseY < y+squareWidth
 && mousePressed==true) {//cursor touches the square
 fill(random(255), random(255), random(255));
 rect(0, 0, squareWidth, squareWidth);
 }
 popMatrix();
 randomness = randomness + random(0.075);
 }
 }
 //noLoop();
}