> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.p9Bln8y7n92/rev.3
 * 
 * authors: 
 *   Nick Sullivan

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



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.98IQaj7G4-SuE/rev.2



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9L-GsDGR1Yl4F/rev.1



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9rdyGypYn0f5S/rev.1



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9IzptYkjd1tzg/rev.3



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9oIUi0OIxTpWT/rev.2



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Modi", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9A95T6HdpK3fx/rev.1



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Modified clone of 'Conn", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.98dPc8VJ9TmKY/rev.0



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Modified clone of 'Connections'''", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9l6j0XlqjOSni/rev.1



// This sketch builds on a prior work, "Modified clone of 'Modified clone of 'Connections''", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.98hm8B4DRzL2C/rev.1



// This sketch builds on a prior work, "Modified clone of 'Connections'", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9Nz$k27uOHh2u/rev.0



// This sketch builds on a prior work, "Connections", created by Nick Sullivan
// http://studio.sketchpad.cc/sp/pad/view/ro.9etgUn$FJQvtr/rev.4



int sw;
int sh;
int swo;
int sho;
int gw = 500;
int gh = 500;
int w = 100;
int h = 100;

DisplayItems dItems;
int n = 20;


int num = 5;
int timeInc;
PVector[] nodes = new PVector[num];
PVector[] connects = new PVector[num];
PVector[] targets = new PVector[num];
PVector[] easings = new PVector[num];
PVector[] ltargets = new PVector[num];
PVector[] etargets = new PVector[num];
color[] colours = new color[num];

void setup(){
  size(500, 500);
  sw = width;
  sh = height;
  swo = sw / 2;
  sho = sh / 2;
  
  //colorMode(HSB, 100);
  
  //smooth();
  background(0);
  translate(swo, sho);  
  
  //dItems = new DisplayItems(n);
  
  for(int i = 0; i < num; i += 1){
    float theta = i / (float)num * 2 * PI;
    float amp = random(200);
    nodes[i] = new PVector(sin(theta) * amp, cos(theta) * amp);
    
    targets[i] = new PVector(random(-swo, swo), random(-sho, sho));
   
    easings[i] = new PVector(random(0.0005, 0.005), random(0.0005, 0.005));
    
    colours[i] = color(random(255), random(255), random(255));
    
//    for(int j = 0; j < num; j += 1){
//      ltargets[j] = nodes[j];
//    }    
  }
}

void draw(){
  //background(255);
  
  noStroke();
  fill(0, 64);
  rect(0, 0, sw, sh);
  translate(swo, sho);
  
  //dItems.DrawCross();
  //dItems.DrawGrid();
  //dItems.DrawGridPoints(); 
  //dItems.DrawTime();
  
  timeInc += 1;

  for(int i = 0; i < num; i += 1){
    if(timeInc % 1000 == 0){
      targets[i] = new PVector(random(-swo, swo), random(-sho, sho));
    }
    if(timeInc % 500 == 0){
      easings[i] = new PVector(random(0.0005, 0.005), random(0.0005, 0.005));
    }
  
    float dx = targets[i].x - nodes[i].x;
    if(abs(dx) > 1) {
      nodes[i].x += dx * easings[i].x;
    }
    float dy = targets[i].y - nodes[i].y;
    if(abs(dy) > 1) {
      nodes[i].y += dy * easings[i].y;
    }
      
    stroke(colours[i]);
    strokeWeight(10);
    point(nodes[i].x, nodes[i].y);
    
    stroke(255);
    strokeWeight(5);
    point(targets[i].x, targets[i].y);
    
    
    for(int j = 0; j < num; j += 1){
      //if(i != j){
        connects[j] = new PVector(nodes[i].x, nodes[i].y);    
        
        float d = dist(nodes[i].x, nodes[i].y, nodes[j].x, nodes[j].y); 
        if(d < 100){  
          ltargets[j] = targets[j];  
          //connects[j] = new PVector(nodes[i].x, nodes[i].y);  
    
        }else{
          ltargets[j] = new PVector(nodes[i].x, nodes[i].y); 
          //connects[j] = new PVector(nodes[i].x, nodes[i].y);  
          
//          float theta = j / (float)num * 2 * PI;
//          float amp = 20;
//          ltargets[j].x = (sin(theta) * amp) + nodes[i].x;
//          ltargets[j].y = (cos(theta) * amp) + nodes[i].y;
        }
        
        float dxx = ltargets[j].x - nodes[j].x;
        if(abs(dxx) > 1) {
          nodes[j].x += dxx * 0.001;
        }
        float dyy = ltargets[j].y - nodes[j].y;
        if(abs(dyy) > 1) {
          nodes[j].y += dyy * 0.001;
        }
              
      //}
      stroke(colours[i]);
      strokeWeight(1);
      line(nodes[j].x, nodes[j].y, ltargets[j].x, ltargets[j].y); 
      
      //float theta = j / (float)num * 2 * PI;
      //float amp = 100;
      //ltargets[j] = new PVector(sin(theta) * amp, cos(theta) * amp);
      //line(nodes[i].x, nodes[i].y, nodes[i].x + ltargets[j].x, nodes[i].y + ltargets[j].y); 
      
      stroke(colours[i]);
      strokeWeight(10, 32);
      point(nodes[j].x, nodes[j].y);
      //point(nodes[i].x + ltargets[j].x, nodes[i].y + ltargets[j].y);
      
      stroke(255, 1);
      strokeWeight(50);
      point(ltargets[j].x, ltargets[j].y);
    }
  }
}