metti le cose in ordine che si capisce meglio

codice:
function avvia() {
   tempo1 = window.setInterval("tempo()", 10);


   function tempo() {
      ctx.clearRect(0, 0, myCanvas.width, myCanvas.height);
      if (dx == 1) {
         x++;
         if (x >= 280) {
            dx = -1
         }
      }
      if (dx == -1) {
         x--;
         if (x <= 0) {
            dx = 1
         }
      }
      if (dy == 1) {
         y++;
         if (y >= 180) {
            dy = -1
         }
      }
      if (dy == -1) {
         y--;
         if (y <= 0) {
            dy = 1
         }
      }
      ctx.beginPath()
      ctx.strokeStyle = "red";
      ctx.lineWidth = 4;
      ctx.fillStyle = "blue"
      ctx.arc(10 + x, 10 + y, 10, 0, 2 * Math.PI);
      ctx.fill();
      ctx.stroke();
      ctx.closePath();
   }
}




function ferma() {
   clearInterval(tempo1);
}