createCanvas(windowWidth, windowHeight);
let fr = floor(frameRate());
if(frameCount % 60 == 0) {
text('avg. frame rate: ' + af, 0, 10);
text('particles: ' + particles.length, 0, 23);
qtree = QuadTree.create();
for (let p of particles) {
let point = new Point(p.x, p.y, p);
range = new Circle(p.x, p.y, p.nd);
p.checkNeighbor(qtree.query(range));
function mousePressed() {
particles.push(new Dot());
function mouseDragged() {
particles.push(new Dot());
this.r = Math.ceil(random(255))
this.g = Math.ceil(random(255))
this.b = Math.ceil(random(255))
this.size = random(4, 10);
this.nd = map(this.size, 4, 10, 80, 100);
this.xSpeed = random(-3, 3)
this.ySpeed = random(-3, 3)
this.neighborCount = map(this.size, 4, 10, 1, 3);
let dotColor = 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + this.a + ')';
if (this.x < 0 || this.x > windowWidth) this.xSpeed = -this.xSpeed;
if (this.y < 0 || this.y > windowHeight) this.ySpeed = -this.ySpeed;
if (this != other || other.neighbors.length > 0) {
var part_dist = dist(this.x, this.y, other.x, other.y);
let dotColor = 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + this.a + ')';
stroke(this.r, this.g, this.b, map(part_dist, 0, this.nd, 255, 1));
strokeWeight(map(part_dist, 0, this.nd, this.size * 0.70, 1));
line(this.x, this.y, other.x, other.y);
if(i>this.neighborCount) break;