<canvas width="600" height="400"></canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
let colores = ["blue", "red", "green"];
pincel.fillStyle = "lightgray";
pincel.fillRect(0, 0, 600, 400);
let i = 1;
var color = "blue";
function cambiarColor() {
if (i < 3) {
color = colores[i];
i++;
} else {
i = 0;
color = colores[i];
}
console.log(i, color);
}
function dibujarCirculo(evento) {
let x = evento.pageX - pantalla.offsetLeft;
let y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = color;
pincel.beginPath();
pincel.arc(x, y, 10, 0, 2 * 3.14);
pincel.fill();
}
pantalla.onclick = dibujarCirculo;
pantalla.oncontextmenu = cambiarColor;
</script>