const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let X, Y;
document.addEventListener('mousemove', function(e) {
X = e.clientX;
Y = e.clientY;
});
function drawRect(x, y, w, h) {
const dx = x + w / 2;
const dy = y + h / 2;
const angle = Math.atan2(X - dx, Y - dy);
ctx.save();
ctx.translate(dx, dy);
ctx.rotate(-angle);
ctx.translate(-dx, -dy);
ctx.strokeRect(x, y, w, h);
ctx.restore();
}
function draw() {
ctx.clearRect(0, 0, innerWidth, innerHeight);
drawRect(50, 50, 50, 50);
requestAnimationFrame(draw);
}
draw();