<canvas width="600" height="400"> </canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
var colores = ["blue", "red", "green", "yellow"];
var indiceColor = 0
pincel.fillStyle = "grey" ;
pincel.fillRect(0,0,600,400);
function exibirAlerta(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
console.log(evento);
alert(x + ","+ y);
}
function dibujarCirculo(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = colores[indiceColor];
pincel.beginPath();
pincel.arc(x,y,10,0,2*3.14);
pincel.fill();
console.log(x + "y" + y);
}
function cambiarColor(){
indiceColor++;
while(indiceColor >=colores.length){
indiceColor = 0;
}
return false;
}
// pantalla.onclick = exibirAlerta;
pantalla.onclick = dibujarCirculo;
pantalla.oncontextmenu = cambiarColor;
</script>