// Initialize some variables. float rippler = 0; float rotation = 0; float[][] boxPos = new float[31][31]; float[][] boxPosNew = new float[31][31]; // Set up the the environment. void setup () { size(600, 400); framerate(40); colorMode(RGB, 1.0); noStroke(); } // Draw the squares. void draw () { background(0.5); translate(300, 200); // Set the "master" translation for all of the squares. rotate(rotation); // And the "master" rotation. pushMatrix(); for( int i=0; i<31; i++ ) { for( int j=0; j<31; j++ ) { pushMatrix(); if( (i==16) & (j==16) ) { boxPosNew[i][j] = -sin(rippler)*2; // The square in the middle is the "rippler" -- it generates the movement. } else { boxPosNew[i][j] = (boxPos[i][abs(j-1)%31]+boxPos[i][(j+1)%31]+boxPos[abs(i-1)%31][j]+boxPos[(i+1)%31][j])/4; // All of the other squares only respond to the movement of those around them. } rotate(boxPosNew[i][j]*30); translate(-155+i*10, -155+j*10); float iFloat = i; // Converts the "i" and "j" int variables into floats. Don't know if this is the best way to do it... float jFloat = j; fill(color(1-sqrt(abs(boxPosNew[i][j])), sqrt(abs(boxPosNew[i][j])))); rect(-5-abs(boxPosNew[i][j]*5), -5-abs(boxPosNew[i][j]*5), 5+abs(boxPosNew[i][j]*5), 5+abs(boxPosNew[i][j]*5)); // Draw the squares. popMatrix(); } } for( int i=0; i<31; i++ ) { for( int j=0; j<31; j++ ) { boxPos[i][j] = boxPosNew[i][j]; // Copy the position data into the "older" array. } } popMatrix(); rotation -= 0.001; // Increment the motion variables. rippler += 0.02; }