xxxxxxxxxx
let numPerSide = 10;
let numAgents = numPerSide * numPerSide;
let agents = [];
function setup() {
createCanvas(500, 500);
colorMode(RGB, 1.0, 1.0, 1.0);
background(1.0, 1.0, 1.0);
frameRate(5)
let unit = width / numPerSide;
for (let i = 0; i < numPerSide; i++) {
for (let j = 0; j < numPerSide; j++) {
let c = color(1.0, 1.0, 1.0);
agents[i * numPerSide + j] = new Agent(i * unit + 0.5 * unit, j * unit + 0.5 * unit, unit * 0.25, c);
}
}
}
function draw() {
background(1.0,1.0,1.0);
for (let i = 0; i < numAgents; i++){
agents[i].evolve();
agents[i].display();
}
}
class Agent {
constructor(x_pos, y_pos, rad, col) {
this.x = x_pos;
this.y = y_pos;
this.radius = rad;
this.d = 2 * rad;
this.c = col;
this.r = red(col);
this.g = green(col);
this.b = blue(col);
}
evolve() {
this.c = color(random(1.0), random(1.0), random(1.0));
}
display() {
noStroke();
fill(this.c);
ellipse(this.x, this.y, this.d, this.d);
}
}