xxxxxxxxxx
84
// if you need a LinkedIn background, use 1584 x 396 px
const planets = 50; // amount of planets. If too many planets vs separation vs space, while loop does not end
const dmin = 60; // minimum distance to avoid overlap
const randomLine = 0.05; // value between 0.1-1.0. The amount is proportional of the chance of a line being drawn. So that not all planets are connecting to all other planets.
let posx = [];
let posy = [];
let counter = 0;
let xt;
let yt;
function setup() {
// createCanvas(1584, 396);
createCanvas(600, 600);
background(255);
// draw border
// fill(255);
// strokeWeight(0.5);
// stroke(0);
// square(48, 48, 404);
// square(50, 50, 400);
fill(0);
stroke(0);
// for (let i = 0; i < width; i = i + 100) {
// circle(i, 0, 5);
// circle(0, i, 5);
// }
// initial node
// posx.push(0);
// posy.push(0);
for (let p = 0; p < planets; p++) {
print("planet: " + p);
while (counter < planets) {
// aestethic random nodes outside borders
let rx = random(-200, 800);
let ry = random(-200, 800);
checkDistance(rx, ry);
}
}
print("planets: " + posx.length);
}
function draw() {
// background(220);
}
function checkDistance(rx, ry) {
print("rx,ry: " + rx, ry);
// print("checkDistance called");
for (let j = 0; j < posx.length; j++) {
print("j: " + j + " length: " + posx.length);
let d = dist(rx, ry, posx[j], posy[j]);
print("distance: " + d);
if (d < dmin) {
print("distance < dmin, start over with new random coord. ");
return true; // if not conditional, will always return after j=0
} else {
if (random(0, 1) < randomLine) {
strokeWeight(random(0.2, 3));
line(rx, ry, posx[j], posy[j]);
}
}
}
// if condition is never true ( < dmin) then = false, then add coordinates
counter++;
posx.push(rx);
posy.push(ry);
circle(rx, ry, random(4, 60));
return false;
}
function keyPressed() {
saveCanvas("Networkism00", "png");
}