我在那里发现了类似的问题,但没有答案。我画了一个圆,就像这样
ctx.strokeStyle='rgb(0,0,0)';
ctx.lineWidth=10;
ctx.beginPath();
ctx.arc(100,100,45,0,Math.PI*2,true);
ctx.closePath();
ctx.stroke();
这给出了一个半径为45的圆,加上5的线宽,使它成为半径为50的圆。现在,我想绘制完全相同的圆圈,但颜色不同,并且只有原始圆周的1/4 (想想Xbox360红色的末日戒指)。所以我试了一下
ctx.strokeStyle='rgb(0,250,0)';
ctx.lineWidth=10;
ctx.beginPath();
ctx.arc(100,100,45,0,Math.PI/2,true); //use 1/4 of original angle
ctx.closePath();
ctx.stroke();
但是连接第一个和最后一个点真的很烦人(有时我想知道是谁创建了画布元素,比如在嵌入文本时,但不要让我开始讨论这个问题……)
发布于 2011-03-26 08:22:00
我已经注释掉了你不想要的那行。通过调用closePath()
,您将关闭您的弧的路径。
示例
JavaScript
ctx.strokeStyle='rgb(0,250,0)';
ctx.lineWidth=10;
ctx.beginPath();
ctx.arc(100,100,45,0,Math.PI/2,true); //use 1/4 of original angle
//ctx.closePath();
ctx.stroke();
jsFiddle。
https://stackoverflow.com/questions/5439462
复制相似问题