Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas arc() Method

HTML canvas arc() Method

Canvas Object Reference Canvas object

Example

Creates a circle:

Your browser does not support the canvas tag.

JavaScript:

var

c

=

document

.

getElementById

(

"

myCanvas

"

)

;

var

ctx

=

c

.

getContext

(

"

2d

"

)

;

ctx

.

beginPath

(

)

;

ctx

.

arc

(

100

,

75

,

50

,

0

,

2

Math

.

PI

)

;

ctx

.

stroke

(

)

;

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the arc() method.

**Note:** Internet Explorer 8 and earlier versions do not support .


Definition and Usage

The arc() method creates an arc/curve (used to create a circle or part of a circle).

**Tip:** To create a circle with arc(), set the start angle to 0 and the end angle to 2*Math.PI.

**Tip:** Please use stroke() or fill() The method draws the actual arc on the canvas.

Center:

arc(

100,75

,50,0Math.PI,1.5Math.PI)

Start angle:

arc(100,75,50,

0

,1.5*Math.PI)

End angle:

arc(100,75,50,0*Math.PI,

1.5*Math.PI

)

JavaScript syntax: context.arc(x,y,r,sAngle,eAngle,counterclockwise);

Parameter value

Parameters Description
x The x-coordinate of the center of the circle.
y The y-coordinate of the center of the circle.
r The radius of the circle.
sAngle The start angle, in radians (the 3 o'clock position of the arc is 0 degrees).
eAngle The end angle, in radians.
counterclockwise Optional. Specifies whether to draw counterclockwise or clockwise. False = clockwise, true = counterclockwise.

Canvas Object Reference Canvas object