# [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线，弧线，圆形)

arc：画弧度

cxt.arc( x, y, 半径, 开始角度，结束角度，是否逆时针 );

x, y: 为弧度的中心横坐标和纵坐标，如果这是画一个圆.那么x,y就是圆的圆心.

 1 <style>
2 body {
3     background: #000;
4 }
5 #canvas{
6     background:white;
7 }
8 </style>
9 <script>
11     var oCanvas = document.querySelector( "#canvas" ),
12         oGc = oCanvas.getContext( '2d' ),
13         width = oCanvas.width, height = oCanvas.height;
14
15     oGc.arc( width / 2, height / 2, height / 2, 0, 270 * Math.PI / 180, true );
16     oGc.stroke();
17 }
18 </script>
20 <body>
21 <canvas id="canvas" width="600" height="300"></canvas>

oGc.arc( width / 2, height / 2, height / 2, 0, 270 * Math.PI / 180, false );

1 oGc.arc( width / 2, height / 2, height / 2, 0, 270 * Math.PI / 180, true );
2 oGc.closePath();
3 oGc.stroke();
1 oGc.arc( width / 2, height / 2, height / 2, 0, 270 * Math.PI / 180, false );
2 oGc.closePath();
3 oGc.stroke();

 1 <style>
2 body {
3     background: #000;
4 }
5 #canvas{
6     background:white;
7 }
8 </style>
9 <script>
11     var oCanvas = document.querySelector( "#canvas" ),
12         oGc = oCanvas.getContext( '2d' );
13
14     oGc.beginPath();
15     oGc.strokeStyle = '#09f';
16     oGc.arc( 150, 150, 150, 0, 360 * Math.PI / 180 );
17     oGc.closePath();
18     oGc.stroke();
19
20     oGc.beginPath();
21     oGc.strokeStyle = 'orange';
22     oGc.arc( 450, 150, 150, 0, 360 * Math.PI / 180 );
23     oGc.closePath();
24     oGc.stroke();
25 }
26 </script>
28 <body>
29 <canvas id="canvas" width="600" height="300"></canvas>
30 </body>

 1     oGc.beginPath();
2     oGc.fillStyle = '#09f';
3     oGc.arc( 150, 150, 150, 0, 360 * Math.PI / 180 );
4     oGc.closePath();
5     oGc.fill();
6
7     oGc.beginPath();
8     oGc.fillStyle = 'orange';
9     oGc.arc( 450, 150, 150, 0, 360 * Math.PI / 180 );
10     oGc.closePath();
11     oGc.fill();

画一个圆角：

 1 <style>
2 body {
3     background: #000;
4 }
5 #canvas{
6     background:white;
7 }
8 </style>
9 <script>
11     var oCanvas = document.querySelector( "#canvas" ),
12         oGc = oCanvas.getContext( '2d' );
13
14     oGc.moveTo( 150, 50 );
15     oGc.lineTo( 250, 50 );
16     oGc.stroke();
17
18     oGc.beginPath();
19     oGc.arc( 250, 100, 50, 270 * Math.PI / 180, 0, false );
20     oGc.moveTo( 300, 100 );
21     oGc.lineTo( 300, 200 );
22     oGc.stroke();
23 }
24 </script>
28 </body>