xxxxxxxxxx
34
let base = 0;
let calibrate;
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
}
function draw() {
let eulerAngles = [mouseX, 0, 0];
if (calibrate) {
base = eulerAngles[0];
calibrate = false;
}
let angle = eulerAngles[0] - base;
clear();
rotateAbout(angle, 200, 100);
fill('green');
rect(150, 50, 100, 150);
}
function mouseClicked() {
base = -mouseX;
calibrate = true;
}
/** Rotates a shape the amount specified by the angle
* parameter, around the point (x, y).
*/
function rotateAbout(angle, x, y) {
translate(x, y);
rotate(angle);
translate(-x, -y);
}