1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| const canvas = document.querySelector(".canvas"); const ctx = canvas.getContext("2d");
let scaleValue = 1; let rotationValue = 0;
function toRadian(degree) { return (degree * Math.PI) / 180; }
function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.translate(250, 250); ctx.scale(scaleValue, scaleValue); ctx.rotate(toRadian(rotationValue)); ctx.strokeRect(-50, -50, 100, 100); ctx.restore();
scaleValue += 0.01; rotationValue -= 2; requestAnimationFrame(draw); }
draw();
|