xxxxxxxxxx
39
let walker1, walker2;
function setup() {
createCanvas(600, 600);
walker1 = new Walker(width / 6, height / 2, color(255, 150));
walker2 = new Walker((2 * width) / 3, height / 2, color(0, 255, 0)); //There's something about the color green in the usage of lines against a black backdrop that gives a "retro" feeling
background(0);
}
function draw() {
walker1.update();
walker1.display();
walker2.update();
walker2.display();
}
class Walker {
constructor(x, y, col) {
this.pos = createVector(x, y);
this.prevPos = this.pos.copy();
this.col = col;
}
update() {
this.prevPos.set(this.pos);
let step = createVector(random(-5.5, 5.5), random(-7, 7));
this.pos.add(step);
this.pos.x = constrain(this.pos.x, 0, width);
this.pos.y = constrain(this.pos.y, 0, height);
}
display() {
stroke(this.col);
line(this.prevPos.x, this.prevPos.y, this.pos.x, this.pos.y);
}
}