HTML canvas bezierCurveTo()Method

Canvas 对象参考手册Canvas Object

Example

Draw a cubic Bézier curve:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

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

Try it Yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support the bezierCurveTo() method.

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


Definition and Usage

The bezierCurveTo() method adds a point to the current path by using the specified control points that represent a cubic Bézier curve.

A cubic Bézier curve requires three points. The first two points are control points used in the cubic Bézier calculation, and the third point is the end point of the curve. The start point of the curve is the last point in the current path. If the path does not exist, then use thebeginPath()andmoveTo()method to define the start point.

三次贝塞尔曲线

Start point:
moveTo(20,20)
Control point 1:
bezierCurveTo(20,100,200,100,200,20)
Control point 2:
bezierCurveTo(20,100,200,100,200,20)
End point:
bezierCurveTo(20,100,200,100,200,20)

Tip:Please see thequadraticCurveTo()method. It has one control point instead of two.


JavaScript Syntax: context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);

Parameter Values

Parameter Description
cp1x The x-coordinate of the first Bézier control point.
cp1y The y-coordinate of the first Bézier control point.
cp2x The x-coordinate of the second Bézier control point.
cp2y The y-coordinate of the second Bézier control point.
x The x-coordinate of the end point.
y The y-coordinate of the end point.


Canvas 对象参考手册Canvas Object

Other Extensions