<!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>Bolinha / Bolão</title>
</head>
<body>
<canvas
style="border-radius: 8px"
id="drawArea"
width="600"
height="400"
></canvas>
<script>
var painting = document.querySelector("#drawArea");
var brushTool = painting.getContext("2d");
brushTool.fillStyle = "lightgrey";
brushTool.fillRect(0, 0, 600, 400);
var colors = ["blue", "red", "green", "violet"];
var setColor = 0;
radius = 10;
function drawCircle(event, color) {
var x = event.pageX - painting.offsetLeft;
var y = event.pageY - painting.offsetTop;
if (event.shiftKey && radius < 40) {
if (radius + 10 < 40) {
radius = radius + 10;
} else {
radius = 40;
}
}
if (event.altKey && radius > 10) {
if (radius - 5 > 10) {
radius = radius - 5;
} else {
radius = 10;
}
}
color = colors[setColor];
brushTool.fillStyle = color;
brushTool.beginPath();
brushTool.arc(x, y, radius, 0, 2 * Math.PI);
brushTool.fill();
}
painting.onclick = drawCircle;
function changeColor() {
setColor++;
if (setColor >= colors.length) {
setColor = 0;
}
return false;
}
painting.oncontextmenu = changeColor;
</script>
</body>
</html>