W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
畫一條弧線。
Tip: 創(chuàng)建一個(gè)圓可以用arc()
方法指定起始弧度為0,終止弧度為2 * Math.PI
。
Tip: 用stroke()
或者fill()
方法來在 canvas 中畫弧線。
參數(shù) | 類型 | 說明 |
---|---|---|
x | Number | 圓的x坐標(biāo) |
y | Number | 圓的y坐標(biāo) |
r | Number | 圓的半徑 |
sAngle | Number | 起始弧度,單位弧度(在3點(diǎn)鐘方向) |
eAngle | Number | 終止弧度 |
counterclockwise | Boolean | 可選。指定弧度的方向是逆時(shí)針還是順時(shí)針。默認(rèn)是false,即順時(shí)針。 |
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)
的三個(gè)關(guān)鍵坐標(biāo)如下:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: