<canvas width="600" height="400"></canvas>
<script>
let lienzo = document.querySelector("canvas");
let pincel = lienzo.getContext("2d");
var colores = ["green", "blue", "red"];
let i = 0;
pincel.fillStyle = "grey";
pincel.fillRect(0,0,600,400);
function disenharCircunferencia(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 x = 0
var limite = false;
function actualizarPantalla(){
if(limite == false){
limpiarPantalla();
disenharCircunferencia(x,20,10);
x++;
if(x >= 600){
limite = true;
}
} else {
limpiarPantalla();
disenharCircunferencia(x,20,10);
x--;
if(x <= 0){
limite = false;
}
}
}
setInterval(actualizarPantalla,1);
</script>