xxxxxxxxxx
let agents = [];
const agentCount = 3000;
const cycle = 500;
const step = 5;
class Agent {
constructor() {
this.x = random(width);
this.y = random(height);
let n = this.x + this.y - 2 * frameCount;
let rem = ((n % cycle) + cycle) % cycle;
this.color = rem < cycle / 2 ? "black" : "white";
}
update() {
let angle = noise(this.x / width, this.y / height) * 100;
stroke(this.color);
line(
this.x,
this.y,
(this.x += cos(angle) * step),
(this.y += sin(angle) * step)
);
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
while (agents.length < agentCount) {
agents.push(new Agent());
}
agents.forEach((a) => a.update());
agents = agents.filter(
(a) => random(5) > 1 && a.x > 0 && a.y > 0 && a.x < width && a.y < height
);
}