HTML:
<canvas width="600" height="400"></canvas>
Javascript:
var tela = document.querySelector("canvas");
var pincel = tela.getContext("2d");
pincel.fillStyle = "grey";
pincel.fillRect(0, 0, 600, 400);
colors = ["blue", "red", "green"];
var indice = 0;
function desenhaCirculo(evento) {
var x = evento.pageX - tela.offsetLeft;
var y = evento.pageY - tela.offsetTop;
pincel.fillStyle = colors[indice];
pincel.beginPath();
pincel.arc(x, y, 10, 0, 2 * 3.14);
pincel.fill();
}
tela.onclick = desenhaCirculo;
function mudaCor() {
if(indice < colors.length){
indice++;
console.log(indice);
}
if (indice === colors.length) {
indice = 0;
}
return false;
}
tela.oncontextmenu = mudaCor;