Double For Loop With Mouse Interaction
/* double 'for loop' with mouse interaction
 * homework made by Cym on November 12, 2009
 */

int segments;
float sizeX;
float sizeY;
float distanceX;
float distanceY;

void setup() {
  frameRate(5);
  size (400, 400);
  segments = 25;
  sizeX = width/segments;
  sizeY = height/segments;
}

void draw() {
   background(0);
   noStroke();

   for (int nY=0; nY<=width; nY+=sizeY) {     
     for (int nX=0; nX<=height; nX+=sizeX) {
       distanceX = abs(mouseX - nX);
       distanceY = abs(mouseY - nY);
       fill(255-((((distanceX/width)*255)+((distanceY/height)*255)))/2);
       rect (nX,nY,sizeX,sizeY);
     }
   }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License