Draw a Bezier curve in JavaScript

Description

The following code shows how to draw a Bezier curve.

Example


<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function(){<!--from  w w  w . ja v a 2s .co  m-->
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");

context.lineWidth = 10;
context.strokeStyle = "black"; // line color
context.moveTo(180, 130);
context.bezierCurveTo(150, 10, 420, 10, 420, 180);
context.stroke();
};
</script>
</head>
<body>
<canvas id="myCanvas" width="600" height="250" style="border:1px solid black;">
</canvas>
</body>
</html>

Click to view the demo

The code above generates the following result.

Draw a Bezier curve in JavaScript