/

HTML / CSS / JavaScript Tutorial

JavaScript canvas2d object method: arcTo()

[this page | pdf | back links]

The arcTo() method of the JavaScript DOM object returned by the getContext("2d") method applied to the HTML <canvas> element creates a circular arc between two tangents.

 

It has the following syntax with the following parameters.

 

context.arcTo(x, y, r, startAngle, endAngle, counterclockwise)

 

Parameter

Required / Optional

Description

xstart

Required

x-coordinate of start tangent

ystart

Required

y-coordinate of start tangent

xend

Required

x-coordinate of end tangent

yend

Required

y-coordinate of end tangent

r

Required

Radius of arc

 

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", "200");
x2.setAttribute("style", "border: 1px solid black");
var c2 = x2.getContext("2d");
c2.beginPath();
c2.moveTo(20, 30);
c2.lineTo(60, 30);
c2.arcTo(110, 30, 110, 80, 50);
c2.lineTo(110, 120);
c2.stroke();
document.getElementById("element").appendChild(x2);
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodCanvas2dArcTo() {
  var x = document.createElement("CANVAS"); var c = x.getContext("2d"); return !!c.arcTo;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile