2012-05-04 71 views
0

custom shape in canas畫布中的自定義形狀?

有什麼方法可以在html5畫布中使用'bezier曲線'或'二次曲線'創建形狀。或者是有什麼在畫布

+0

你曾經在畫布上重新創建過這個形狀嗎? –

+0

不,我用圖像而不是繪製路徑 – sumitmann

回答

1

對於多邊形你可以使用以下(其中CTX是你的畫布的getContext( '2D')):

ctx.fillStyle=*hex code of the color you want it to be"; 
ctx.beginPath(); 
ctx.moveTo(x1,y1); 
ctx.lineTo(x2,y2); 
ctx.lineTo(x3,y3); 
*add more points if needed using a lineTo(x,y) for each of your points* 
ctx.closePath(); 
ctx.fill(); 

如果你想有一個行程多邊形使用ctx.strokeStyle和ctx.stroke()而不是ctx.fillStyle和ctx.fill ()