<canvas width="600" height="400"></canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
pincel.fillStyle = "grey";
pincel.fillRect(0,0,600,400);
function disenarCirculo(x,y,radio){
pincel.fillStyle = "blue";
pincel.beginPath();
pincel.arc(x,y,radio,0,2*Math.PI);
pincel.fill();
}
function limpiarPantalla(){
pincel.clearRect(0,0,600,400);
}
var i =0;
var sentido=1;
function graficar(){
limpiarPantalla();
if(i > 600){
sentido = -1;
}else if(i < 0){
sentido = 1;
}
disenarCirculo(i,20,10);
i = i + sentido;
}
setInterval(graficar, 5);
// disenarCirculo(20,20,10)
</script>