<canvas width="600" height="400"> </canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
pincel.fillStyle = "lightgrey";
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);
pincel.fillStyle = "lightgrey";
pincel.fillRect(0,0,600,400);
}
var inicial=20
var x = 0;
var diam=20;
var ida=1;
var y=inicial;
function mouse(evento){
y=evento.pageY - pantalla.offsetTop;
}
function actualizarPantalla(evento){
limpiarPantalla();
pantalla.onclick=mouse;
disenharCircunferencia(x,y,diam);
if (x!=600-diam && ida==1) {
x++;if(x==600-diam)ida=0;
}if (x!=diam && ida==0) {
x--;if(x==diam)ida=1;
}
// y=evento.pageY - pantalla.offsetTop;
}
setInterval(actualizarPantalla,1);
</script>