> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.h9Ucn9MZnCU/rev.1512
 * 
 * authors: 
 *   Vilson Vieira

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



int dragged = -1;
int nX, nY;
int delay=5;
int count = 30;
int maxSize = 100;
int minSize = 40;
float[][] e = new float[count][6];
int sel = 0;
boolean dragging=false;

void mouseDragged(){
  dragging=true;
}

void mouseReleased(){
  dragging=false;
}

void setup(){
  frameRate(10);
  size(1024, 768);
  strokeWeight(0.5);
  for(int j=0;j< count;j++){
      e[j][0]=random(width); // X 
      e[j][1]=random(height); // Y
      e[j][2]=random(minSize,maxSize); // Radius        
      e[j][3]=random(-.5,.5); // X Speed
      e[j][4]=random(-.5,.5); // Y Speed    
      e[j][5]=random(120,220); // green color component
    }
  }

void draw() {
  background(255);
  
  for (int j=0; j<count; j++) {
    float radi = e[j][2];
    float diam = radi/2;

    for(int k=0;k< count;k++){
      if( dist(e[j][0],e[j][1],e[k][0],e[k][1]) < radi*3){
        noFill();
        stroke(100);
        for (int foo=0; foo<5; foo=foo+1) {
        bezier(e[j][0]+random(-20,20), e[j][1]+random(-20,20), e[j][0]+random(-1,1), e[j][1]+random(-1,1), e[k][0]+random(-1,1), e[k][1]+random(-1,1), e[k][0]+random(-20,20), e[k][1]+random(-20,20));
        
        }
      }
    }
  }
  noStroke();
  for (int j=0;j< count;j++) {
     float radi=e[j][2];
     float diam=radi/2;
  
     if( dist(e[j][0],e[j][1],mouseX,mouseY) < radi){
         fill(25, 180, 25);
          if (dragging){
            if (dragged == -1)
               dragged = j;
            if (dragged == j) {
              e[j][0] = mouseX; //(mouseX-e[j][0])/delay;//mouseX;
              e[j][1] = mouseY; //(mouseY-e[j][1])/delay;//mouseY;
            }
          } else {
            dragged = -1;
          }
       } else {
    fill(25, e[j][5], 25);
    }
    rectMode(CENTER);
    rect(e[j][0],e[j][1],radi,radi);
    //e[j][0]+=e[j][3] ;
    //e[j][1]+=e[j][4];
     
    if( e[j][0] < -diam      ){ e[j][0] = width+diam;  } 
    if( e[j][0] > width+diam ){ e[j][0] = -diam;       }
    if( e[j][1] < 0-diam     ){ e[j][1] = height+diam; }
    if( e[j][1] > height+diam){ e[j][1] = -diam;       }
}
    
  }