xxxxxxxxxx
let particles = [];
let leader = []
let a = 0
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 255)
background((150 + 200) / 2, 255, 255);
let x = -width / 10
let y = - height / 10
for (let j = 0; j < 50; j++) {
for (let i = 0; i < 100; i++) {
let particle = {
position: createVector(x, y)
};
particle.color = color(map(particle.position.x + particle.position.y, 0, width + height, 0, 255), random(200, 255), random(100, 255), 20);
//colorMode()
particles.push(particle);
x = x + ((width + width/5) / 50)
}
leader.push(createVector(random(width), random(height)))
x = - width / 10
y = y + ((height + height / 5) / 50)
}
}
function draw() {
//background(255, 1);
let speedRate = map(cos(frameCount / 100), -1, 1, 100, 5000)
for (let i = 0; i < particles.length; i++) {
let p = particles[i].position;
let pP = particles[(i - 1 + particles.length) % particles.length].position; // wrap around to the last particle
if (i > 0) {
let d = dist(p.x, p.y, (pP.x + leader[0].x) / 2, (pP.y + leader[0].y) / 2);
p.x += sin(d) * random([random(5), 0.5]); // adjusting the movement scale for better visualization
p.y += cos(d) * random([random(5), 0.5]); // adjusting the movement scale for better visualization
} else {
let d = dist(p.x, p.y, leader[0].x, leader[0].y);
p.x += sin(d) * random([random(5), 0.5]); // adjusting the movement scale for better visualization
p.y += cos(d) * random([random(5), 0.5]); // adjusting the movement scale for better visualization
}
stroke(particles[i].color); // Set stroke color to particle's color
strokeWeight(10)
point(p.x, p.y);
if (frameCount % map(cos(a / 20), -1, 1, 75, 500) < map(sin(a / 10), -1, 1, 10, 50)) {
a = a + 0.00001
} else {
strokeWeight(40)
colorMode(RGB)
stroke(255, 255, 0)
// point(leader[0].x, leader[0].y)
}
leader[0].x = (map(sin(a), -1, 1, 0, width) + map(noise(a), -1, 1, 0, width)) / 2
leader[0].y = (map(cos(a), -1, 1, 0, height) + map(noise(a), -1, 1, 0, height)) / 2
/* / Reset particle's position if it goes out of the canvas boundaries
if (p.x > width + width / 5 || p.x < - width / 5 || p.y > height + height / 5 || p.y < - height / 5) {
let randomIndex = floor(random(1, particles.length));
p.x = particles[randomIndex].position.x;
p.y = particles[randomIndex].position.y;
}
*/
}
}