Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas bezierCurveTo() Method

HTML canvas bezierCurveTo() Method

HTML canvas Reference HTML canvas Reference Manual

Example

Draws a cubic Bezier 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 »


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 .


Definition and Usage

The bezierCurveTo() method adds a point to the current path using the specified control points that define a cubic Bezier curve.

A cubic Bezier curve requires three points. The first two are control points used in the cubic Bezier calculation, and the third is the endpoint of the curve. The start point of the curve is the last point in the current path. If no path exists, use beginPath() and moveTo() the 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:** See the quadraticCurveTo() method. It has one control point instead of two.

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

Parameter value

Parameters Description
cp1x The x-coordinate of the first Bezier control point.
cp1y The y-coordinate of the first Bezier control point.
cp2x The x-coordinate of the second Bezier control point.
cp2y The y-coordinate of the second Bezier control point.
x The x-coordinate of the end point.
y The y-coordinate of the end point.

HTML canvas Reference HTML canvas Reference Manual