Resources/misc/blinky_squares.pjs
changeset 0 80c32ef237c6
equal deleted inserted replaced
-1:000000000000 0:80c32ef237c6
       
     1 
       
     2 void setup() {
       
     3 	size( 510, 510 );
       
     4 	smooth();
       
     5 
       
     6 	background( 200 );
       
     7 }
       
     8 
       
     9 void draw() {
       
    10 	if ( mousePressed ) {
       
    11 		rects(1);
       
    12 	}
       
    13 	else {
       
    14 		rects(0);
       
    15 	}
       
    16 }
       
    17 
       
    18 void rects( int rand ) {
       
    19 	int cwidth = 50;
       
    20 	int cheight = 50;
       
    21 
       
    22 	int curwidth = cwidth-(cwidth/5);
       
    23 	int curheight = cheight-(cwidth/5);
       
    24 
       
    25 	noStroke();
       
    26 
       
    27 	for ( int y = cheight/5; y <= height; y += cheight ) {
       
    28 		for ( int x = cwidth/5; x <= width; x += cwidth ) {
       
    29 			if ( rand == 1 ) {
       
    30 				fill( random(180,220) );
       
    31 			} 
       
    32 			else {
       
    33 				fill( 210 );
       
    34 			}
       
    35 
       
    36 			if ( (mouseX > x) && (mouseX < x + curwidth) &&
       
    37 					(mouseY > y) && (mouseY < y + curheight) ) { 
       
    38 
       
    39 				// mouse is inside rectangle
       
    40 			}
       
    41 			else {
       
    42 				rect( x, y, curwidth, curheight );
       
    43 			}
       
    44 		}
       
    45 	}
       
    46 }
       
    47