画布中圆弧的不同 fillStyle 颜色
我想这个问题的解决方案非常简单,如果这是非常明显的,请提前道歉,但我似乎无法弄清楚如何为两个不同的弧设置两个不同的 fillStyles ...我只是想能够绘制不同的彩色圆圈。下面我介绍了我通常如何在画布中使用其他形状/绘图方法来完成此操作,但由于某种原因,对于弧线,它将两个弧线设置为最后一个 fillStyle。
ctx.fillStyle = "#c82124"; //red
ctx.arc(15,15,15,0,Math.PI*2,true);
ctx.fill();
ctx.fillStyle = "#3370d4"; //blue
ctx.arc(580,15,15,0,Math.PI*2,true);
ctx.fill();
I imagine the solution to this is very simple, and apologize in advance if this is painfully obvious, but I can't seem to figure out how to set two different fillStyles for two different arcs ...I just wanna be able to draw different color circles. Below I have how I would normally do it with other shapes/drawing methods in canvas, but for some reason with arcs it sets both arcs to the last fillStyle.
ctx.fillStyle = "#c82124"; //red
ctx.arc(15,15,15,0,Math.PI*2,true);
ctx.fill();
ctx.fillStyle = "#3370d4"; //blue
ctx.arc(580,15,15,0,Math.PI*2,true);
ctx.fill();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您错过了开始和结束路径语句。尝试以下操作(它在 jsfiddle 中对我有用,请参阅此处)
I think you're missing the begin and end path statements. Try the following (it works for me in jsfiddle, see here)
请注意,路径只是几何图形。您可以在
fill( )
之前随时设置.fillStyle
。Note that the path is just the geometry. You can set
.fillStyle
anytime up until thefill( )
.我用
beginPath()
函数尝试过,它成功了。我希望这些对您有用:-
I tried it with the
beginPath()
function and it worked.I hope these works for you to:-