xxxxxxxxxx
64
let walkers;
function setup() {
background(200);
noStroke();
createCanvas(400, 400);
walkers = [];
for (let i = 0; i < 10; i++) {
walkers.push(new Walker(random(0, width), random(0, height), random(1, 1), random(1, 1)));
}
}
function draw() {
//for(let i=0; i<10; i++){
for (let i = 0; i < walkers.length; i++) {
walkers[i].display();
walkers[i].move();
}
}
class Walker {
constructor(tx, ty, tsize, tspeed) {
//width and height
this.x = tx;
this.y = ty;
this.size = tsize;
this.speed = tspeed;
}
display() {
fill(40);
ellipse(this.x, this.y, this.size, this.size);
}
move() {
// this.x += ((random(this.speed * -1, this.speed)));
// this.y += ((random(this.speed * -1, this.speed)));
this.xStep = ((random(-1, 2)));
this.yStep = ((random(-1, 1)));
let move = random(1);
this.x += this.xStep;
this.y += this.yStep;
this.x = constrain(this.x,0,width-1);
this.y = constrain(this.y,0,height-1);
}
}