xxxxxxxxxx
39
let a = 0;
let aVel = 0;
let aAcc = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
}
let pAngle = 0;
function mouseDragged() {
let v1 = createVector(pmouseX - width / 2, pmouseY - height / 2);
pAngle = v1.heading();
}
function mouseReleased() {
let v2 = createVector(mouseX - width / 2, mouseY - height / 2);
aVel = v2.heading() - pAngle;
}
function draw() {
// aAcc = map(mouseX, 0, width, -0.01, 0.01);
// aVel = constrain(aVel, -0.2, 0.2);
if (mouseIsPressed) {
let v3 = createVector(mouseX - width / 2, mouseY - height / 2);
a = v3.heading();
}
background(220);
noStroke();
rectMode(CENTER);
translate(width / 2, height / 2);
rotate(a);
rect(0, 0, 100, 50);
a += aVel;
aVel += aAcc;
}