xxxxxxxxxx
31
let walkers = []; // initiate the walkers array
function setup() {
createCanvas(windowWidth, windowHeight);
initWalkers();
}
function draw(){
drawWalkers();
moveWalkers();
}
function initWalkers(){
for(let i = 0; i < 100; i++){ // loop to create 100 walkers
let w = createVector(random(width), random(height)); // create a random vector
walkers.push(w) // add the walker to the walkers array
}
}
function drawWalkers(){
for(let i = 0; i < 100; i++){ // loop to display the 100 walkers
circle(walkers[i].x, walkers[i].y, 10); // display walker at index i
}
}
function moveWalkers() {
for(let i = 0; i < 100; i++){ // loop to display the 100 walkers
walkers[i].x += random(-5,5); // update walkers[i] x position
walkers[i].y += random(-5,5); // update walkers[i] y position
}
}