40 lines
851 B
JavaScript
40 lines
851 B
JavaScript
let canvas = document.querySelector('#scene');
|
|
|
|
canvas.width = document.body.clientWidth;
|
|
canvas.height = document.body.clientHeight;
|
|
|
|
let ctx = canvas.getContext('2d');
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle
|
|
|
|
// les fonctions
|
|
function degToRad(deg) {
|
|
return deg * (Math.PI / 180.0);
|
|
}
|
|
|
|
// les animations
|
|
// une loop ne peut pas focntionner car l'image ne se rafraîchit pas entre les iteration de boucle
|
|
// for (let index = 0; index < array.length; index++) {
|
|
|
|
// }
|
|
|
|
let pos = {
|
|
x:50,
|
|
y:50
|
|
}
|
|
|
|
let monAnime = function(){
|
|
// pos.x = pos.x +1;
|
|
// pos.x += 1;
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
|
|
pos.x++;
|
|
ctx.beginPath();
|
|
ctx.arc(pos.x, pos.y, 20, 0, degToRad(360));
|
|
ctx.stroke();
|
|
|
|
window.requestAnimationFrame(monAnime);
|
|
}
|
|
|
|
|
|
window.requestAnimationFrame(monAnime); |