1
resposta

Elaborei Assim - Mais Simples que Imaginava!!

O meu código ficou assim, no início achei que ficaria enorme, mas a solução foi mais simples que imaginei!

<canvas width="600" height="400"></canvas>

<script>
    var tela = document.querySelector('canvas');
    var pincel = tela.getContext('2d');
    pincel.fillStyle = 'grey';
    pincel.fillRect(0, 0, 600, 400);

    function desenhaCirculo(evento) {

        var x = evento.pageX - tela.offsetLeft;
        var y = evento.pageY - tela.offsetTop;
        pincel.fillStyle = cores[i];
        pincel.beginPath();
        pincel.arc(x, y, 10, 0, 2 * 3.14);
        pincel.fill();
        console.log(x + ',' + y);
    }

    tela.onclick = desenhaCirculo;

    var cores = ['blue', 'red', 'green'];
    var i = 0
    function mudaCor() {

        pincel.fillStyle = cores[i];
        i++

        if (i == 3) {
            i = 0
        }
        return false;
    }

    tela.oncontextmenu = mudaCor;

</script>
1 resposta

Olá, Ronaldo! Tudo bem por aí?

Mandou bem! Parabéns!

Ficou com alguma dúvida durante a resolução?

Caso tenha ficado não deixe de compartilhar com a gente.

Continue praticando, bons estudos e até mais! =)