fractalkitty looking for math? fractalkitty.com

all

constellations percolate

#random#classes#interactive#animation#sky

nodesnNodemaxNconnectionsnConnectionseideticIDeideticFiltersaMemorylapseOfTimepercolate



let nodes = [];
let nNode = 8;
let maxN = 14;
let connections = [];
let nConnections = 0;
let eideticID = 0;
let eideticFilters = [];
function setup() {
  nNode = floor(random(7, maxN));
  createCanvas(600, 600);
  strokeWeight(1);
  cnt = 0;
  d = width;
  background(50, 60, 70);
  for (let i = 0; i < nNode; i++) {
    for (let j = 0; j < nNode; j++) {
      x = -width / 2 + (i * d) / nNode + 40;
      y = -height / 2 + (j * d) / nNode + 40;
      x = random(-d / 2 + 40, d / 2 - 40);
      y = random(-d / 2 + 40, d / 2 - 40);
      nodes.push(new aMemory(x, y));
      cnt++;
    }
  }
}
function draw() {
  background(20);
  translate(width / 2, height / 2);
  for (let i = 0; i < nodes.length; i++) {
    nodes[i].display();
  }
  for (let i = 0; i < connections.length; i++) {
    connections[i].display();
    connections[i].simplify();
  }
  for (let i = 0; i < min(2, frameCount); i++) {
    percolate();
  }
  percolate();
}

class aMemory {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.nC = 0;
  }
  display() {
    noStroke();
    fill(255);
    circle(this.x, this.y, 3);
  }
}

class lapseOfTime {
  constructor(x1, y1, x2, y2, num1) {
    this.n = num1;
    this.x1 = x1;
    this.y1 = y1;
    this.x2 = x2;
    this.y2 = y2;
    eideticFilters[eideticID] = color(
      random(100, 255),
      random(100, 255),
      random(100, 255),
      100
    );
    this.eideticID = eideticID;
    eideticID++;
  }
  simplify() {
    for (let i = 0; i < nConnections; i++) {
      if (
        this.x1 == connections[i].x1 &&
        this.y1 == connections[i].y1 &&
        this.n != i
      ) {
        this.eideticID = min(this.eideticID, connections[i].eideticID);
      }
      if (
        this.x2 == connections[i].x2 &&
        this.y2 == connections[i].y2 &&
        this.n != i
      ) {
        this.eideticID = min(this.eideticID, connections[i].eideticID);
      }
      if (
        this.x2 == connections[i].x1 &&
        this.y2 == connections[i].y1 &&
        this.n != i
      ) {
        this.eideticID = min(this.eideticID, connections[i].eideticID);
      }
      if (
        this.x1 == connections[i].x2 &&
        this.y1 == connections[i].y2 &&
        this.n != i
      ) {
        this.eideticID = min(this.eideticID, connections[i].eideticID);
      }
    }
  }
  display() {
    stroke(eideticFilters[this.eideticID]);
    line(this.x1, this.y1, this.x2, this.y2);
    fill(eideticFilters[this.eideticID]);
    for (let i = 0; i < 5; i++) {
      circle(this.x1, this.y1, 10);
      circle(this.x2, this.y2, 10);
    }
  }
}

function mousePressed() {
  for (let i = 0; i < 100; i++) {
    percolate();
  }
}

function percolate() {
  p = floor(random(0, nodes.length - 0.0001));
  q = floor(random(0, nodes.length - 0.00001));
  distpq = dist(nodes[p].x, nodes[p].y, nodes[q].x, nodes[q].y);
  checkD = distpq < min(100, 100 - (nNode * nNode) / 3) + 20;
  checkC = true;
  for (let i = 0; i < connections.length; i++) {
    tmp =
      connections[i].x1 === nodes[p].x &&
      connections[i].y1 === nodes[p].y &&
      connections[i].x2 === nodes[q].x &&
      connections[i].y2 === nodes[q].y;
    if (tmp) {
      checkC = false;
    } else {
    }
  }
  nCheck = nodes[p].nC < nNode && nodes[q].nC < nNode;
  if (checkC && p != q && nCheck && checkD) {
    connections.push(
      new lapseOfTime(
        nodes[p].x,
        nodes[p].y,
        nodes[q].x,
        nodes[q].y,
        nConnections
      )
    );
    nConnections++;
    nodes[p].nC++;
    nodes[q].nC++;
  }
}

function keyPressed() {
  nodes = [];
  nNode = 8;
  connections = [];
  nConnections = 0;
  eideticID = 0;
  eideticFilters = [];
  setup();
  draw();
}