## INTRODUCTION

Bezier curves are interesting – used mostly for drawing “S” shapes or asymmetric curves.

(Picture from : http://www.html5canvastutorials.com/tutorials/html5-canvas-bezier-curves/)

Bezier curves are defined by a context point, like quadratic curves, two control points that define two tangents, and an ending point.

The first part of the curve is tangential to the imaginary line defined by the context point and the first control point. The second part of the curve is tangential to the imaginary line defined by the second control point and the ending point.

The best way to understand how they work is to check out one of these interactive applications:

## TYPICAL USAGE OF BEZIER CURVES

Source code:

- ctx.moveTo(contextX, contextY);
- context.bezierCurveTo(controlX1, controlY1, controlX2, controlY2, endX, endY);
- // Optional : set lineWidth and stroke color
- context.lineWidth = 5;
- context.strokeStyle = “#0000ff”;
- // Draw!
- ctx.stroke();

## EXAMPLE 1

Try this interactive example: http://jsbin.com/hodawa/2/edit

- context.beginPath();
- context.moveTo(100, 20);
- context.bezierCurveTo(290, –40, 200, 200, 400, 100);
- context.lineWidth = 5;
- context.strokeStyle = “#0000ff”;
- context.stroke();

## EXAMPLE 2 WITH LINES, QUADRATIC, AND BEZIER CURVES IN A PATH

Try this example online: http://jsbin.com/wifowa/1/edit

Extract from source code:

- context.beginPath();
- context.moveTo(100, 20);
- context.lineTo(200, 160);
- context.quadraticCurveTo(230, 200, 250, 120);
- context.bezierCurveTo(290, –40, 300, 200, 400, 150);
- context.lineTo(500, 90);
- // TRY COMMENTING THIS LINE OUT
- context.closePath();
- context.lineWidth = 5;
- context.strokeStyle = “#0000ff”;
- context.stroke();

In this example we use the closePath() method to draw a line between the last path point and the first path point (line 11), so that the drawing looks like a pair of goggles.

Note how the different parts are linked together and make a “path”:

## INTERESTING, INTERACTIVE TOOL FOR GENERATING CODE THAT DRAWS BEZIER CURVES

This tool is available online: http://www.victoriakirst.com/beziertool/, try it!

Screenshot: