3
試圖將半圓區域劃分爲HTML畫布中的彩色片段。 這裏是我的嘗試,如何使用HTML畫布將半圓區域劃分爲彩色片段
ctx.save();
ctx.translate(c.width/2, (c.height/2)-1);
ctx.strokeStyle = "red"
ctx.lineWidth = 3;
ctx.lineCap = "round";
var x=400; // number of times lineTo strokes. Greater the value the better is the smoothness
var factor=1; //with =1, the entire semicirular region is filled.
for (var i = 0; i < x; i++) {
//ctx.rotate(Math.PI);
ctx.beginPath();
ctx.strokeStyle = "rgba(255,0,0,1)";
//ctx.rotate(-Math.PI/2);
ctx.rotate((-Math.PI * factor)/x);
//1st color segment, factor=1 helps to paint 100% of semicircular region
ctx.moveTo(122, 0);
ctx.lineTo(70, 0);
ctx.stroke();
//ctx.rotate(Math.PI); //2nd color segment
另一種方法,可能是使用同心圓弧()段。我現在正在嘗試。但任何能夠拋出一些光的人都會很有幫助。
你基本上要求餅圖,對吧? – Phrogz 2011-01-13 15:09:17