JavaScript canvas2d object method: bezierCurveTo()
[this page | pdf | back links]
The
bezierCurveTo() method of
the JavaScript
DOM object
returned by the getContext("2d")
method applied to the HTML <canvas>
element creates a cubic Bézier curve. To create a quadratic Bézier curve use
the quadraticCurveTo()
method.
 
It has the following
syntax with the following parameters.
 
context.bezierCurveTo(x, y, r, startAngle,
endAngle, counterclockwise)
 
 
  | Parameter | Required / Optional | Description | 
 
  | pt1x | Required | x-coordinate of first
  control point of curve | 
 
  | pt1y | Required | y-coordinate of first
  control point of curve | 
 
  | pt2x | Required | x-coordinate of second
  control point of curve | 
 
  | pt2y | Required | y-coordinate of second
  control point of curve | 
 
  | x | Required | x-coordinate of end
  point | 
 
  | y | Required | y-coordinate of end
  point | 
 
EXAMPLE:
HTML USED IN THIS EXAMPLE:
| <!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
<span id="element"></span>
<script>
var x2 = document.createElement("CANVAS");
x2.setAttribute("width", "200");
x2.setAttribute("height", "100");
x2.setAttribute("style", "border: 1px solid black");
var c2 = x2.getContext("2d");
c2.strokeStyle = "blue";
c2.beginPath();
c2.moveTo(30, 10);
c2.quadraticCurveTo(20,90,70,95,145,20);
c2.stroke();
document.getElementById("element").appendChild(x2);
</script>
</body>
</html>
 | 
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
| function isSupportedJavaScriptMethodCanvas2dBezierCurveTo() {
  var x = document.createElement("CANVAS"); var c = x.getContext("2d"); return !!c.bezierCurveTo;
} | 
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)