int rectMax,timer = 1000,tDelay = 1000,bgcolor = 0,stkColor = 255;
int rectSize,rectAlpha,bottom,w = 800,h = 600;
int angle = 0,cd,ca = 1;
float ra = -1.0,aa = 1.0;
boolean strokeOff = true, resetBG = false;
void setup() {
frameRate(30);
size( w,h );
smooth();
background( bgcolor );
rectMax = int( h * 0.70 );
rectSize = rectMax;
rectAlpha = 128;
}
void mouseMoved() {
timer = 0;
cursor(ARROW);
}
void keyPressed() {
if ( keyCode == UP ) {
rectAlpha += 5;
if (rectAlpha > 255) {
rectAlpha = 255;
}
}
if ( keyCode == DOWN ) {
rectAlpha -= 5;
if (rectAlpha < 0) {
rectAlpha = 0;
}
}
if ( key == ' ' ) {
strokeOff = !strokeOff;
}
if ( key == 'r' ) {
rectSize = rectMax;
background( bgcolor );
}
}
void draw() {
if ( resetBG ) {
background( bgcolor );
resetBG = false;
}
timer += 1;
cd += ca;
if ( strokeOff ) {
noStroke();
}
else {
stroke( stkColor );
}
fill( cd,rectAlpha );
translate( w / 2,h / 2 );
rotate( radians(angle) );
rectMode( CENTER );
rect( 0,0,rectSize,rectSize );
if ( timer < tDelay ) {
rectSize -= ( mouseY - h / 2 ) * 0.05;
angle += ( mouseX - w / 2 ) * 0.05;
}
else {
// no mouse input for tDelay frames so
// it's time to automate the rects
noCursor();
if ( random(25) > 24 ) {
aa *= -1;
}
if ( random(25) > 24 ) {
ra = -1 * random( 1 );
}
rectSize += ra;
angle += aa;
}
if ( rectSize < 1 ) {
rectSize = 0;
if ( timer > tDelay ) {
//delay(2000);
resetBG = true;
strokeOff = true;
rectAlpha = round( random(255) );
rectSize = rectMax;
}
}
if ( rectSize > rectMax ) {
rectSize = rectMax;
if ( timer > tDelay ) {
background( 255,0,255 );
}
}
if ( cd > 254 ) {
ca = -1;
}
if ( cd < 1 ) {
ca = 1;
}
}
[top]