> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.WeasXAM039e/rev.5
 * 
 * authors: 
 *   GoToLoop

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



/**
 * Conglomerate of Points (v2.01)
 * Janosch & GoToLoop (2016-Feb-01)
 *
 * forum.Processing.org/two/discussion/14709/simple-p3-sketch-to-p5-js
 * studio.ProcessingTogether.com/sp/pad/export/ro.9lMOG-RZX8JDk
 *
 * p5js.ProcessingTogether.com/sp/pad/export/ro.CYuAGs4xyhzhKu
 * CodePen.io/anon/pen/ZQjQmK?editors=0010#0
 */

static final float EASE = .07;
static final int QTY = 10, DIAM = 10, FAR = 0xFF, NEAR = 20, AWAY = 150;
final PVector[] points = new PVector[QTY], tPoints = new PVector[QTY];

void setup() {
  size(1000, 650, 1/2 != 1/2.? FX2D : JAVA2D);
  smooth(4);
  frameRate(60);

  strokeWeight(.5);
  colorMode(RGB, FAR);
  ellipseMode(CENTER);

  for (int i = 0; i < QTY; ++i) {
    points[i]  = new PVector(random(width), random(height));
    tPoints[i] = new PVector(random(width), random(height));
  }
}

void draw() {
  background(243, 239, 232);

  for (int i = 0; i < QTY; ++i) {
    final float xdist = tPoints[i].x - points[i].x;
    final float ydist = tPoints[i].y - points[i].y;

    final float x = points[i].x += EASE * .5 * xdist;
    final float y = points[i].y += EASE * .5 * ydist;

    for (int j = i + 1; j < QTY; ++j) {
      final float dst = dist(x, y, points[j].x, points[j].y);

      if (dst < FAR) {
        stroke(205, 106, 104, FAR - dst);
        line(x, y, points[j].x, points[j].y);
      }
    }

    final float distance = .5 * (xdist*xdist + ydist*ydist);

    noStroke();
    fill(205, 106, 104, 200 - distance*EASE);     
    ellipse(x, y, DIAM, DIAM);

    if (distance <= NEAR) {
      points[i].set(tPoints[i]);

      tPoints[i].x = mouseX + random(-AWAY, AWAY);
      tPoints[i].y = mouseY + random(-AWAY, AWAY);
    }
  }
}