<meta charset="UTF-8">
<canvas width="600" height="400"> </canvas>
<script>
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 indice_color_actual = 0;
function dibujar_circulo(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = colores[indice_color_actual];
pincel.beginPath();
pincel.arc(x,y,10,0,2*3.14);
pincel.fill();
}
function cambiar_color() {
indice_color_actual++;
if(indice_color_actual>= colores.length) {
indice_color_actual = 0;
}
return false;
}
pantalla.onclick = dibujar_circulo;
pantalla.oncontextmenu = cambiar_color;
</script>