Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API drawing addColorStop (create color gradient point)


May 19, 2021 WeChat Mini Program Development Document


Table of contents


WeChat small program API drawing addColorStop (create color gradient point) Drawing interfaces and methods


canvasContext.addColorStop


Defined

Create a gradient point for the color.

Tip: The portion less than the minimum stop is rendered as the color of the minimum stop, and the portion greater than the maximum stop is rendered as the color of the maximum stop.

Tip: You need addColorStop() to specify a gradient point, at least two.

Parameters

Parameters Type Defined
stop Number(0-1) Represents the position of the gradient point at the start and end points
color Color The color of the gradient point

Example

const ctx = wx.crateCanvasContext('myCanvas')

// Create circular gradient
const grd = ctx.createCircularGradient(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()

WeChat small program API drawing addColorStop (create color gradient point)

WeChat small program API drawing addColorStop (create color gradient point) Drawing interfaces and methods