<!DOCTYPE html>
<html lang="pt-br">
<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>Bolinha</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
var cores = ['blue','red','green']
var cor = 0
context.fillStyle = 'grey';
context.fillRect(0, 0, 600, 400);
var raio = 10
var desenha = false
canvas.addEventListener('mousemove', function (evento) {
if(desenha)
var x = evento.pageX - canvas.offsetLeft;
var y = evento.pageY - canvas.offsetTop;
if (evento.shiftKey)
if(raio <= 40)
raio+=20;
if(evento.altKey)
if(raio>10)
raio-=5;
context.fillStyle = cores[cor]
context.beginPath();
context.arc(x, y, raio, 0, 2 * 3.14);
context.fill();
})
function mudarCor(){
cor++
if(cor >= cores.length){
cor = 0
}
return false;
}
canvas.addEventListener('mousedown', function(){
desenha = true
})
canvas.addEventListener('mouseup', function(){
desenha = false
})
canvas.addEventListener("contextmenu", mudarCor)
</script>
</body>
</html>