CanvasContext.arc

解释:画一条弧线。

方法参数

参数名属性必填默认值说明
xNumber圆的 x 坐标
yNumber圆的 y 坐标
rNumber圆的半径
sAngleNumber起始弧度,单位弧度(在3点钟方向)
eAngleNumber终止弧度
counterclockwiseBooleanfalse,即顺时针指定弧度的方向是逆时针还是顺时针。

示例

扫码体验

CanvasContext.arc - 图1请使用百度APP扫码

图片示例

图片

代码示例1 :

在开发者工具中预览效果

  1. const canvasContext = swan.createCanvasContext('myCanvas');
  2. canvasContext.arc(100, 75, 50, 0, 2 * Math.PI);
  3. canvasContext.setFillStyle('blue');
  4. canvasContext.fill();
  5. canvasContext.draw();

图片示例

CanvasContext.arc - 图3

CanvasContext.arc - 图4

CanvasContext.arc - 图5

代码示例2 - 连续画弧 :

在开发者工具中预览效果

  1. Page({
  2. onReady() {
  3. let canvasContext = swan.createCanvasContext('canvas1');
  4. canvasContext.arc(100, 98, 40, 0, 2 * Math.PI);
  5. canvasContext.setFillStyle('blue');
  6. canvasContext.fill();
  7. canvasContext.setLineWidth(6);
  8. canvasContext.setStrokeStyle('#FFB7DD');
  9. canvasContext.setLineCap('round')
  10. canvasContext.beginPath();
  11. canvasContext.arc( 75, 65, 20, Math.PI * 0.75, Math.PI * 1.85, false);
  12. canvasContext.arc( 115, 60, 20, Math.PI * 1.15, Math.PI * 2.15, false);
  13. canvasContext.arc( 140, 90, 20, Math.PI * 1.55, Math.PI * 2.45, false);
  14. canvasContext.arc( 125, 125, 20, Math.PI * 1.75, Math.PI * 2.75, false);
  15. canvasContext.arc( 90, 135, 20, Math.PI * 2.15, Math.PI * 3.15, false);
  16. canvasContext.arc( 60, 105, 20, Math.PI * 2.40, Math.PI * 3.50, false);
  17. canvasContext.closePath();
  18. canvasContext.stroke();
  19. canvasContext.draw();
  20. }
  21. });

代码示例3 - counterclockwise为true :

在开发者工具中预览效果

  1. Page({
  2. onReady: function () {
  3. const canvasContext = swan.createCanvasContext('myCanvas');
  4. canvasContext.arc(100, 75, 50, 2, 2 * Math.PI, true);
  5. canvasContext.setFillStyle('blue');
  6. canvasContext.fill();
  7. canvasContext.draw();
  8. }
  9. });

代码示例4 - counterclockwise为false :

在开发者工具中预览效果

  1. Page({
  2. onReady: function () {
  3. const canvasContext = swan.createCanvasContext('myCanvas');
  4. canvasContext.arc(100, 75, 50, 2, 2 * Math.PI, false);
  5. canvasContext.setFillStyle('blue');
  6. canvasContext.fill();
  7. canvasContext.draw();
  8. }
  9. });