xxxxxxxxxx
let atoms = []; // array
function setup() {
createCanvas(600, 600); //canvas
noLoop();
}
function draw() {
background(240);
let atomCount = int(random(5, 10)); // number of atoms
let centerX = width / 2;
let centerY = height / 2;
// create random atoms
for (let i = 0; i < atomCount; i++) {
let x = centerX + random(-200, 200);
let y = centerY + random(-200, 200);
let atomSize = random(20, 50);
let colorR = random(100, 255);
let colorG = random(100, 255);
let colorB = random(100, 255);
atoms.push({
x,
y,
atomSize,
color: color(colorR, colorG, colorB)
});
}
// draw connections
stroke(50);
strokeWeight(3);
for (let i = 0; i < atoms.length; i++) {
let atomA = atoms[i];
let connections = int(random(1, 4));
for (let j = 0; j < connections; j++) {
let atomB = random(atoms);
if (atomA !== atomB) {
line(atomA.x, atomA.y, atomB.x, atomB.y);
}
}
}
// draw atoms
noStroke();
for (let atom of atoms) {
fill(atom.color);
ellipse(atom.x, atom.y, atom.atomSize);
}
}