let img1, img2;
let nodes;
let nNodes, nConnections;
let connections;
function preload() {
img1 = loadImage("/assets/supergraph.png");
img2 = loadImage("/assets/star.png");
}
function setup() {
createCanvas(600, 600);
makeNodes();
angleMode(DEGREES);
}
function draw() {
t = frameCount;
background(0);
translate(width / 2, height / 2);
background(img1);
for (let i = 0; i < nNodes; i++) {
s = nodes[i].z;
image(img2, nodes[i].x - s / 2, nodes[i].y - s / 2, s, s);
}
for (let i = 0; i < nConnections; i++) {
if (i > nConnections / 2) {
stroke(255);
strokeWeight(0.2);
fill(255);
} else {
stroke(255 * abs(sin(t / 2)));
strokeWeight(0.2);
}
line(
nodes[connections[i].x].x,
nodes[connections[i].x].y,
nodes[connections[i].y].x,
nodes[connections[i].y].y
);
}
if (frameCount % 360 === 0) {
makeNodes();
}
}
function makeNodes() {
nodes = [];
connections = [];
nNodes = int(random(50, 100));
nConnections = int(min(random(nNodes, nNodes * 2), 10));
for (let i = 0; i < nNodes; i++) {
nodes[i] = createVector(
random(-width / 2 + 10, width / 2 - 10),
random(-height / 2 + 10, height / 2 - 10),
random(2, 30)
);
}
connections[0] = createVector(
int(random(0, nNodes - 1)),
int(random(0, nNodes - 1))
);
for (let i = 1; i < nConnections; i++) {
connections[i] = createVector(
connections[i - 1].y,
int(random(0, nNodes - 1))
);
}
}