帆布定制形状?

时间:2012-05-04 09:50:13

标签: html5 canvas

custom shape in canas

有没有办法在html5画布中使用'bezier Curve'或'quadratic curve'创建形状。或者是否有任何方法在画布中绘制多边形

2 个答案:

答案 0 :(得分: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()

答案 1 :(得分:0)

当然可以,至少你有:

  • 到quadraticCurveTo
  • bezierCurveTo

查看此示例代码:

http://www.html5canvastutorials.com/labs/html5-canvas-playing-card-suits/

相关问题