微信小程序开发 专题
专题目录
您的位置:微信小程序开发 > 微信小程序开发专题 > 使用arc()方法在微信小程序canvas中画弧线
使用arc()方法在微信小程序canvas中画弧线
作者:--    发布时间:2019-11-20



定义

画一条弧线。

tip: 创建一个圆可以用arc()方法指定起始弧度为0,终止弧度为2 * math.pi

tip: 用stroke()或者fill()方法来在 canvas 中画弧线。

参数

参数类型说明
xnumber圆的x坐标
ynumber圆的y坐标
rnumber圆的半径
sanglenumber起始弧度,单位弧度(在3点钟方向)
eanglenumber终止弧度
counterclockwiseboolean可选。指定弧度的方向是逆时针还是顺时针。默认是false,即顺时针。

例子

const ctx = wx.createcanvascontext('mycanvas')

// draw coordinates
ctx.arc(100, 75, 50, 0, 2 * math.pi)
ctx.setfillstyle('#eeeeee')
ctx.fill()

ctx.beginpath()
ctx.moveto(40, 75)
ctx.lineto(160, 75)
ctx.moveto(100, 15)
ctx.lineto(100, 135)
ctx.setstrokestyle('#aaaaaa')
ctx.stroke()

ctx.setfontsize(12)
ctx.setfillstyle('black')
ctx.filltext('0', 165, 78)
ctx.filltext('0.5*pi', 83, 145)
ctx.filltext('1*pi', 15, 78)
ctx.filltext('1.5*pi', 83, 10)

// draw points
ctx.beginpath()
ctx.arc(100, 75, 2, 0, 2 * math.pi)
ctx.setfillstyle('lightgreen')
ctx.fill()

ctx.beginpath()
ctx.arc(100, 25, 2, 0, 2 * math.pi)
ctx.setfillstyle('blue')
ctx.fill()

ctx.beginpath()
ctx.arc(150, 75, 2, 0, 2 * math.pi)
ctx.setfillstyle('red')
ctx.fill()

// draw arc
ctx.beginpath()
ctx.arc(100, 75, 50, 0, 1.5 * math.pi)
ctx.setstrokestyle('#333333')
ctx.stroke()

ctx.draw()


针对arc(100, 75, 50, 0, 1.5 * math.pi)的三个关键坐标如下:

  • 绿色: 圆心 (100, 75)
  • 红色: 起始弧度 (0)
  • 蓝色: 终止弧度 (1.5 * math.pi)

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册