溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微信小程序中canvasContext.arc怎么用

發(fā)布時間:2022-03-05 11:37:06 來源:億速云 閱讀:502 作者:小新 欄目:開發(fā)技術

這篇文章將為大家詳細講解有關微信小程序中canvasContext.arc怎么用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

canvasContext.arc


定義

畫一條弧線。

Tip: 創(chuàng)建一個圓可以用arc()方法指定起始弧度為0,終止弧度為2 * Math.PI。

Tip: 用stroke()或者fill()方法來在 canvas 中畫弧線。

參數(shù)

參數(shù) 類型 說明
x Number 圓的x坐標
y Number 圓的y坐標
r Number 圓的半徑
sAngle Number 起始弧度,單位弧度(在3點鐘方向)
eAngle Number 終止弧度
counterclockwise Boolean 可選。指定弧度的方向是逆時針還是順時針。默認是false,即順時針。

例子

const ctx = wx.createCanvasContext('myCanvas')// Draw coordinatesctx.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 pointsctx.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 arcctx.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)

關于“微信小程序中canvasContext.arc怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI