xxxxxxxxxx
45
/*
These two objects rotate in their display methods.
The second one currently rotates around the other one.
Change their display method so that each object rotates
independently of the other.
*/
let p1;
let p2;
function setup() {
createCanvas(600, 600);
p1 = new Rotater(width/2, height/2);
p2 = new Rotater(150, 150);
}
function draw() {
background(255);
p1.update();
p1.display();
p2.update();
p2.display();
}
class Rotater {
constructor(x, y){
this.x = x;
this.y = y;
this.angle = 0;
}
display() {
rectMode(CENTER);
translate(this.x, this.y);
rotate(radians(this.angle));
rect(0, 0, 100, 100);
}
update() {
this.angle++;
}
}