[英]HTML canvas: drawing separated circles
I wanted to draw some circles on the canvas with the following layout: A circle right in the centre of the canvas and four circles at the mid points of the four edges of the canvas. 我想在画布上用以下布局绘制一些圆:在画布中央的一个圆圈,在画布四个边缘的中点的四个圆圈。 I've put up my code here jsfiddle . 我在jsfiddle放置了我的代码。 The circles are rendered, however there are multiple filled paths between them too, resulting in an amalgamated mess. 圆被渲染,但是它们之间也有多个填充路径,从而导致混乱。
I'm drawing all the circles by using 我正在使用绘制所有圆圈
ctx.arc(points[i].x, points[i].y, radius, 0, 2 * Math.PI, true);
How do I remove them ? 如何删除它们?
Put closePath
after each circular-arc so that the circles are not connected: 在每个圆弧之后放置closePath
,以使圆不连接:
ctx.arc(points[i].x, points[i].y, radius, 0, 2 * Math.PI, true);
ctx.closePath();
You are probably wanting to fill after each arc. 您可能想在每个弧后填充。
Something like this should work 这样的事情应该工作
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, true);
ctx.fill();
for(var i = 0; i < points.length; i++){
var _ = points[i];
ctx.beginPath();
ctx.arc(_.x, _.y, 25, 0, 2 * Math.PI, true);
ctx.fill();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.