xxxxxxxxxx
49
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
class Mover {
constructor() {
let x = random(-width / 2, width / 2);
let y = random(-height / 2, height / 2);
this.position = createVector(x, y);
this.velocity = createVector();
this.acceleration = createVector();
this.topspeed = 5;
this.angleY = random(6);
this.angleZ = random(6);
}
update() {
// Compute a vector that points from position to mouse
var mouse = createVector(mouseX - width / 2, mouseY - height / 2);
this.acceleration = p5.Vector.sub(mouse, this.position);
// Set magnitude of acceleration
this.acceleration.setMag(3.03);
this.velocity.add(this.acceleration);
this.velocity.limit(this.topspeed);
this.position.add(this.velocity);
this.angleY += 0.02;
this.angleZ += 0.02;
}
display() {
noStroke(0);
strokeWeight(0.5);
//fill(0);
//blendMode(MULTIPLY);
// textureMode(NORMAL);
push();
translate(this.position.x, this.position.y)
rotateY(this.angleY);
rotateZ(this.angleZ);
texture(img);
box(100);
pop();
}
}