xxxxxxxxxx
38
let stars = [];
let backgroundStars
function setup() {
frameRate(100);
createCanvas(windowWidth, windowHeight);
background(0);
backgroundStars = new BackgroundStar();
for (let i = 0; i < 100; i++) {
stars.push(new Star());
}
}
function draw() {
background(0, 10);
backgroundStars.displayBgStar();
for (let star of stars) {
star.display();
star.update();
star.noOverlap(stars);
star.checkEdges();
}
for (let i = 0; i < stars.length; i++) {
let linesConnected = 0; // Initialize the count of lines connected to the current star
for (let j = i + 1; j < stars.length; j++) {
let d = dist(stars[i].position.x, stars[i].position.y, stars[j].position.x, stars[j].position.y);
// Add a condition to check if the number of lines connected to the star is less than 4
if (d < 100 && linesConnected < 10) {
stroke(stars[i].colors, stars[i].alpha);
line(stars[i].position.x, stars[i].position.y, stars[j].position.x, stars[j].position.y);
linesConnected++; // Increment the count of lines connected to the star
}
}
}
}