Демо JavaScript:
<canvas id="paintbox" width="500" height="200"></canvas><br /> <input type="button" onclick="start()" value="Пуск"> <input type="button" onclick="stop()" value="Стоп"> <script> x=10; var ctx; ctx = document.getElementById('paintbox').getContext('2d'); function start(){ Idint = setInterval(draw, 100); } function draw() { ctx.fillStyle = 'white'; ctx.fillRect(x,10,50,50); x=x+3; ctx.fillStyle = 'blue'; ctx.fillRect(x,10,50,50); } function stop() { clearInterval(Idint); } </script>