Nic*_*ick 19 javascript canvas colors fill geometric-arc
我想这个问题的解决方案非常简单,如果这很明显,请提前道歉,但我似乎无法弄清楚如何为两个不同的弧设置两个不同的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();
Run Code Online (Sandbox Code Playgroud)
puk*_*puk 38
我想你错过了开始和结束路径语句.尝试以下(它在jsfiddle中适用于我,请参阅此处)
ctx.fillStyle = "#c82124"; //red
ctx.beginPath();
ctx.arc(15,15,15,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
ctx.fillStyle = "#3370d4"; //blue
ctx.beginPath();
ctx.arc(580,15,15,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44154 次 |
| 最近记录: |