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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>rotation composée</title>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="cancan" width="1000" height="500"></canvas>
<script>
let ctx = document.getElementById("cancan").getContext("2d");
let image = new Image();
image.src = "image.png";
const dgTord= Math.PI/180;
const ctxw=ctx.canvas.width, ctxh=ctx.canvas.height;
const posx = ctxw / 2, posy = ctxh / 2;
const pw=6;
const cx=64, cy=64;//centre de ton image
var angle=0,dx=0;// angle de rotation en degrés et déplacement dx horizontal d'un trait
function newframe() {
draw();
rotation();
window.requestAnimationFrame(newframe);
}
function rotation() {
angle += dgTord;
dx++;
}
function draw() {
ctx.clearRect(0,0,ctxw,ctxh );
ctx.save();
ctx.translate(posx, posy);
ctx.rotate(angle);
ctx.translate(-cx,-cy);
ctx.drawImage(image,0,0);
ctx.restore();
ctx.lineWidth=pw;
ctx.beginPath();
ctx.moveTo(20+dx,posy-pw/2);
ctx.lineTo(dx,posy-pw/2);
ctx.stroke();
}
//setInterval(newframe,1000/60);
window.requestAnimationFrame(newframe);
</script>
</body>
</html> |
Partager