不同的fillStyle颜色为画布中的弧 [英] different fillStyle colors for arc in canvas

查看:252
本文介绍了不同的fillStyle颜色为画布中的弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这个解决方案非常简单,如果这是痛苦明显,提前道歉,但我似乎不知道如何设置两个不同的fillStyles两个不同的弧...我只是想绘制不同的颜色圆。下面我将如何通常使用canvas中的其他形状/绘图方法,但由于某种原因使用弧,它将两个弧设置为最后一个fillStyle。

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();


推荐答案

我想你缺少开始和结束路径语句。尝试以下(它适用于我在jsfiddle,见这里

I think you're missing the begin and end path statements. Try the following (it works for me in jsfiddle, see here)

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();

这篇关于不同的fillStyle颜色为画布中的弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆