fractalkitty looking for math? fractalkitty.com

weekly creative coding

draggable

#random#interactive#animation#accumulates#random-walk#wcc

Drag a dot around to collect other dots and then release them all when you release your mouse.

nodes

let nodes = [];
let n = 2500;
function setup() {
  cnv = createCanvas(windowWidth, windowHeight);
  nodes = [];
  background(20, 30, 40);
  for (let i = 0; i < n; i++) {
    nodes[i] = {
      x: randomGaussian(0, width / 4),
      y: randomGaussian(0, height / 4),
      c1: color(random(100, 200), random(150, 225), random(180, 255)),
      c2: color(random(50, 100), random(70, 125), random(80, 155), 50),
      s: random(2, 20)
    };
  }
}

function draw() {
  translate(width / 2, height / 2);
  if (mouseIsPressed) {
    for (let i = 0; i < nodes.length; i++) {
      if (
        dist(mouseX - width / 2, mouseY - height / 2, nodes[i].x, nodes[i].y) <
        nodes[i].s
      ) {
        nodes[i].x = mouseX - width / 2;
        nodes[i].y = mouseY - height / 2;
      }
    }
  }
  for (let i = 0; i < nodes.length; i++) {
    fill(nodes[i].c1);
    stroke(nodes[i].c2);
    x = nodes[i].x;
    y = nodes[i].y;
    circle(x, y, nodes[i].s);
    nodes[i].x += random(-1, 1);
    nodes[i].y += random(-1, 1);
  }
}