<canvas width="600" height="400"></canvas>
<script type="text/javascript">
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext('2d');
pincel.fillStyle = "grey";
pincel.fillRect(0,0,600,400);
var colores = ["blue","red","green"];
var indexColor = 0 ;
function exibirAlerta(event){
var x = event.pageX - pantalla.offsetLeft;
var y = event.pageY - pantalla.offsetTop;
console.log(event);
alert(x + ", " + y);
}
function dibujarCirculo(event){
var x = event.pageX - pantalla.offsetLeft;
var y = event.pageY - pantalla.offsetTop;
pincel.fillStyle = colores[indexColor];
pincel.beginPath();
pincel.arc(x,y,10,0,2*3.1416);
pincel.fill();
console.log(x + "," + y);
}
pantalla.onclick = dibujarCirculo;
function alterarColor(){
indexColor++;
if(indexColor >= colores.length ){
indexColor = 0;
}
console.log("Funciono");
console.log(indexColor);
//alert("Funciono");
return false;
}
pantalla.oncontextmenu = alterarColor;
</script>