Course contentsShow
← Web Development
Lesson 2618 of 2,98247. Data VisualizationFree lesson

Bezier and Quadratic Curves

Creating smooth curves with quadraticCurveTo and bezierCurveTo for organic shapes.

Bezier and Quadratic Curves

What you'll learn: How to draw smooth, organic curves on the Canvas using quadraticCurveTo() and bezierCurveTo().

While straight paths and arcs get you far, many organic shapes—like waves, clouds, or flowing ribbons—need smooth curves that bend exactly how you want. Canvas provides two methods for this: quadratic curves (one control point) and Bézier curves (two control points).

Quadratic Curves: Single Control Point

Think of quadraticCurveTo() as a string being pulled from the middle. You specify a control point that "pulls" the curve, plus an endpoint:

const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(50, 100);
// quadraticCurveTo(controlX, controlY, endX, endY)
ctx.quadraticCurveTo(150, 20, 250, 100);
ctx.stroke();

The curve starts at (50, 100), bends toward the control point at (150, 20), and ends at (250, 100). The curve never actually touches the control point—it just influences the bend direction.

Bézier Curves: Two Control Points

bezierCurveTo() gives you even more control with two control points, creating S-curves and more complex organic shapes:

ctx.beginPath();
ctx.moveTo(50, 150);
// bezierCurveTo(cp1x, cp1y, cp2x, cp2y, endX, endY)
ctx.bezierCurveTo(100, 50, 200, 250, 250, 150);
ctx.strokeStyle = 'blue';
ctx.stroke();

The first control point influences the curve's departure from the start; the second influences its arrival at the end. This creates incredibly smooth, natural-looking shapes perfect for data visualizations with flowing lines or artistic elements.

Key Takeaway: Use quadraticCurveTo(cpX, cpY, endX, endY) for simple curves with one control point, or bezierCurveTo(cp1X, cp1Y, cp2X, cp2Y, endX, endY) for complex, smooth curves with two control points—essential for creating organic, flowing shapes in your canvas visualizations.