English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
arc() is a Canvas 2The arc() method is a Canvas D API method to draw an arc path. The center of the arc path is at (x, y) position, with a radius of r, and starts drawing from startAngle (default is clockwise) and ends at endAngle.
Draw a circle:
<!DOCTYPE html> <html> <head> <meta charset="utf-8> <title>HTML canvas arc() method usage-Basic Tutorial(oldtoolbag.com)</<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3> Your browser does not support HTML5 canvas tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.beginPath(); ctx.arc(100,75,50,0,2*Math.PI); ctx.stroke(); </script> </body> </html>Test to see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9and Safari support arc() method.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
The arc() method creates an arc./curve (used to create a circle or part of a circle).
Tip:If you create a circle through arc(), please perform the following operations: set the start angle to 0, and set the end angle to2 * Math.PI.
Tip:Please use stroke() orfill() Method to draw an actual arc on the canvas.
JavaScript syntax: | context.arc(x,y,r,sAngle,eAngle,counterclockwise); |
---|
Parameter | Description |
---|---|
x | X coordinate of the center of the circle. |
y | Y coordinate of the center of the circle. |
r | Radius of the circle. |
sAngle | Start angle, in radians (the circular three o'clock position is 0 degrees). |
eAngle | End angle, in radians. |
counterclockwise | Optional. Specifies whether to draw in a clockwise or counterclockwise direction. False = clockwise, true = counterclockwise. |