<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
var colores = ["blue", "red", "green"];
var control = 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 ${y}`);
}
function dibujarCirculo(evento) {
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = colores[control];
pincel.beginPath();
pincel.arc(x, y, 50, 0, 2 * 3.14);
pincel.fill();
console.log(`${x} y ${y}`);
}
pantalla.onclick = dibujarCirculo;
function alterarColor() {
control++;
if(control>=colores.length){
control = 0;
}
return false;
}
pantalla.oncontextmenu = alterarColor;
</script>
</body>
</html>