/**
* An interactive hypnotic rectangle.
*
*
Elie Zananiri
* CART 253, Winter 2008
*/
void setup() {
size(400, 400);
rectMode(CENTER);
noStroke();
}
void draw() {
boolean mode = true;
float offset = min(1.0, max(0.01, mouseX/(width*1.0)));
for (float i=1.0; i > 0; i -= offset) {
hypnoRect(i, mode);
mode = !mode;
}
}
void hypnoRect(float ratio, boolean mode) {
// draw the middle rectangle
fill(mode?0:255);
rect(width/2, height/2, width*ratio, height*ratio);
// draw the corner rectangles
fill(mode?255:0);
rect(width*1/4, height*1/4, width*ratio/2, height*ratio/2);
rect(width*1/4, height*3/4, width*ratio/2, height*ratio/2);
rect(width*3/4, height*3/4, width*ratio/2, height*ratio/2);
rect(width*3/4, height*1/4, width*ratio/2, height*ratio/2);
}