xxxxxxxxxx
41
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let walker1;
let walker2;
function setup() {
createCanvas(640, 360);
walker1 = new Walker(0, 1000, 0.01, 200, 100, 0);
walker2 = new Walker(0, 1000, 0.011, 0, 100, 200);
background(0);
}
function draw() {
walker1.walk();
walker1.display();
walker2.walk();
walker2.display();
}
class Walker {
constructor(xoff, yoff, speed, r, g, b) {
this.position = createVector(width / 2, height / 2);
this.noff = createVector(xoff, yoff);
this.speed = speed;
this.color = color(r, g, b, 50);
}
display() {
fill(this.color);
noStroke();
ellipse(this.position.x, this.position.y, 24);
}
walk() {
this.position.x = map(noise(this.noff.x), 0, 1, 0, width);
this.position.y = map(noise(this.noff.y), 0, 1, 0, height);
this.noff.add(this.speed, this.speed);
}
}