小程序畫布添加顏色的漸變點(diǎn)CanvasGradient.addColorStop
CanvasGradient.addColorStop(number stop, string color)
添加顏色的漸變點(diǎn)。小于最小 stop 的部分會(huì)按最小 stop 的 color 來渲染,大于最大 stop 的部分會(huì)按最大 stop 的 color 來渲染
小程序插件:不支持
參數(shù)
number stop
表示漸變中開始與結(jié)束之間的位置,范圍 0-1。
string color
漸變點(diǎn)的顏色。
示例代碼
const ctx = wx.createCanvasContext('myCanvas')
// Create circular gradient
const grd = ctx.createLinearGradient(30, 10, 120, 10)
grd.addColorStop(0, 'red')
grd.addColorStop(0.16, 'orange')
grd.addColorStop(0.33, 'yellow')
grd.addColorStop(0.5, 'green')
grd.addColorStop(0.66, 'cyan')
grd.addColorStop(0.83, 'blue')
grd.addColorStop(1, 'purple')
// Fill with gradient
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()
作者:大學(xué)生新聞網(wǎng) 來源:大學(xué)生新聞網(wǎng)
發(fā)布時(shí)間:2025-04-17 閱讀:
- 小程序畫布顏色Color
- 顏色。可以用以下幾種方式來表示 canvas 中使用的顏色:
- 04-17 關(guān)注:0