xxxxxxxxxx
50
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let walker1;
let walker2;
var r, g, b;
let step = 5;
function setup() {
createCanvas(640, 360);
walker1 = new Walker(0, 100);
walker2 = new Walker(0.2, 100.2);
background(127);
}
function draw() {
walker1.walk();
walker1.display();
walker2.walk();
walker2.display();
}
class Walker {
constructor(xoff, yoff) {
this.position = createVector(width / 2, height / 2);
this.noff = createVector(xoff, yoff);
this.r = random(255);
this.g = random(255);
this.b = random(255);
}
display() {
strokeWeight(2);
fill(this.r, this.g, this.b, 150);
noStroke();
ellipse(this.position.x, this.position.y, 48, 48);
}
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(0.01, 0.01, 0);
}
}