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
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
canvas {
display: block;
margin: auto;
}
</style>
</head>
<body>
<canvas id="dessin" width="500" height="300"></canvas>
<script>
cadre = document.getElementById('dessin').getContext('2d');
cadre.fillStyle = "rgb(220, 220, 220)";
cadre.fillRect (0, 0, 500, 300);
x = -100;
velo = new Image();
velo.src = 'velo.png';
velo.onload=function() {
cadre.drawImage(velo, -100, 20);
};
bouge = function() {
x=x+2;
if (x>400) x = -100;
cadre.fillRect (0, 0, 500, 300);
cadre.drawImage(velo,x,20);
};
setInterval(bouge, 8);
</script>
</body>
</html> |
Partager