HTML canvas quadraticCurveTo() 方法

定义和用法

quadraticCurveTo() 方法通过使用表示二次贝塞尔曲线的指定控制点,向当前路径添加一个点。

提示:二次贝塞尔曲线需要两个点。第一个点是用于二次贝塞尔计算中的控制点,第二个点是曲线的结束点。曲线的开始点是当前路径中最后一个点。如果路径不存在,那么请使用 beginPath()moveTo() 方法来定义开始点。

Gurɗin Bessel
  • 开始点:moveTo(20,20)
  • 控制点:quadraticCurveTo(20,100,200,20)
  • 结束点:quadraticCurveTo(20,100,200,20)

提示:请查看 bezierCurveTo() 方法。它有两个控制点,而不是一个。

实例

绘制一条二次贝塞尔曲线:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.quadraticCurveTo(20,100,200,20);
ctx.stroke();

Try it yourself

Syntax

context.quadraticCurveTo(cpx,cpy,x,y);

Parameter value

Parameter Description
cpx The x-coordinate of the Bezier control point.
cpy The y-coordinate of the Bezier control point.
x The x-coordinate of the endpoint.
y The y-coordinate of the endpoint.

Browser support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.