xxxxxxxxxx
// 凡庸な悪は文化を壊す
let agents;
const agentsNum = 200;
const threshold = 25;
function setup() {
createCanvas(800, 800);
stroke("black");
fill("lightgray");
agents = Array(agentsNum).fill().map((e) =>(e = {
pos: createVector(random(width), random(height)),
vel: createVector(0, 0),
}));
}
function draw() {
background("white");
for (let i = agents.length; i--; ) {
const current = agents[i];
ellipse(current.pos.x, current.pos.y, 6);
for (let j = i; j--; ) {
const other = agents[j];
const delta = other.pos.copy().sub(current.pos);
const dst = delta.mag();
if (!agents.some((any) =>
dst > any.pos.dist(current.pos) &&
dst > any.pos.dist(other.pos)
)) {
line(current.pos.x, current.pos.y, other.pos.x, other.pos.y);
current.vel.add(delta);
dst > threshold && delta.mult(-1);
other.vel.add(delta);
}
}
}
agents.forEach((a) => {
a.vel.limit(2);
a.pos.add(a.vel);
a.pos.x = constrain(a.pos.x, 0, width);
a.pos.y = constrain(a.pos.y, 0, height);
});
}