I am trying to draw a circle, a clock view, I start at p1 and draw an arc in black using the canvas 2d context, when I reach p1 (full circular tour), I change color to white, and continue to draw, which should give it an effect , as if the black arc was erased, however this does not work properly, because when I change the color of the context, everything changes ...
how to save the first circle in color and draw another on top of it with a different color without changing the color throughout the scene?
here is my attempt
<!DOCTYPE html />
<html>
<head>
<title></title>
<script type="text/javascript">
var i = 0.01;
var Color = "Black";
var x = 75;
var y = 75;
var radius = 20;
var startAngle = 0;
var anticlockwise = false;
function draw() {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.beginPath();
var endAngle = i;
if (Math.floor(endAngle) >= 6) {
i = 0.01;
if (Color == "Black") {
Color = "White";
} else {
Color = "Black";
}
}
ctx.strokeStyle = Color;
ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);
ctx.stroke();
i = i + 0.05;
}
</script>
</head>
<body onload="window.setInterval(function(){draw()},100);">
<canvas id="canvas" width="150" height="150"></canvas>
<span id="display"></span>
</body>
</html>
source
share