Canvas Bézier Curves

Ciprian on Thursday, August 25, 2022 in Canvas

NEW! Learn JavaScript by example. Code snippets, how-to's and tutorials. Try now!

This is a demo for the Canvas: An Awesome Introduction article.

This demonstration shows how Bézier curves can be drawn on a canvas element. Drag the line ends, or the control points to change the curve.

canvas = document.getElementById("canvas");
                                    ctx = canvas.getContext("2d")
                                    ctx.lineWidth = 6;
                                    ctx.strokeStyle = "#333";
                                    ctx.beginPath();
                                    ctx.moveTo(100, 250);
                                    ctx.bezierCurveTo(150, 100, 350, 100, 400, 250);
                                    ctx.stroke();

Related posts

Leave a Reply

You have to agree to the comment policy.