timedt
timedt

Reputation: 1372

Draw a circle with different colored section

So I want to draw a circle, filled blue with a black and red outline. The red part is determined by the look angle. The ctx variable holds the 2d context. Relevant code:

ctx..lineWidth = 0.5
   ..fillStyle = "#0000AA"
   ..strokeStyle = "red";

ctx.beginPath();
ctx.arc(pos.x, pos.y, radius, look - PI / 6, look + PI / 6);
ctx..fill()
   ..closePath()
   ..stroke()
   ..beginPath();
ctx.strokeStyle = "black";
ctx.arc(pos.x, pos.y, radius, look + PI / 6, look - PI / 6);

ctx..fill()
   ..closePath()
   ..stroke();

This, however draws an additional red line inside the circle, that I don't want. How can I get rid of this line?

Upvotes: 0

Views: 96

Answers (1)

markE
markE

Reputation: 105015

Remove the closePath when drawing the red line.

closePath will draw a line connecting the endpoints of your red arc (not what you want).

Upvotes: 1

Related Questions