1. Quadratic Bezier Curve
QuadraticCurveTo(cpx,cpy,x,y) //cpx, cpy represents the coordinates of the control point, x, y represents the end point coordinates;
The mathematical formula is expressed as follows:
The path of the quadratic Bezier curve is traced by the function B (t) given the points P0, P1, P2:
Code example:
Code effect:
2. Cubic Bezier Curve
BezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y) //cp1x, cp1y represents the coordinates of the first control point, cp2x, cp2y represents the coordinates of the second control point, x, y represents the coordinates of the end point ;
The mathematical formula is expressed as follows:
The four points P0, P1, P2, and P3 define a cubic Bezier curve on a plane or in a three-dimensional space. The curve starts from P0 and goes to P1, and from the direction of P2 to P3. Generally it will not pass through P1 or P2; these two points are just there to provide directional information. The distance between P0 and P1 determines "how long" the curve goes in the direction of P2 before turning towards P3.
Code example:
Code rendering:
Isn’t it a cool effect? . . HTML5 canvas is really a fun thing, addictive.