<canvas width="600" height="400"> </canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
pincel.fillStyle = "Dimgrey";
pincel.fillRect(0,0,600,400);
var colors = ["blue","Red", "LawnGreen",]
var posicioActual = 0
function dibujarCirculo(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = colors[posicioActual];
pincel.beginPath();
pincel.arc(x,y,10,0,2*3.14);
pincel.fill();
console.log(x + "," + y);
}
pantalla.onclick = dibujarCirculo;
function alterarColor() {
posicioActual++
if (posicioActual >= colors.length) {
posicioActual = 0
}
return false;
}
pantalla.oncontextmenu = alterarColor;
</script>