画一条弧线。
tip: 创建一个圆可以用arc()
方法指定起始弧度为0,终止弧度为2 * math.pi
。
tip: 用stroke()
或者fill()
方法来在 canvas 中画弧线。
参数 | 类型 | 说明 |
---|---|---|
x | number | 圆的x坐标 |
y | number | 圆的y坐标 |
r | number | 圆的半径 |
sangle | number | 起始弧度,单位弧度(在3点钟方向) |
eangle | number | 终止弧度 |
counterclockwise | boolean | 可选。指定弧度的方向是逆时针还是顺时针。默认是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)
的三个关键坐标如下: