CanvasContext.createLinearGradient

Create a linear gradient. The addColorStop() should be called to specify the gradient point and at least two points should be specified.

Parameters

It is Object type.

PropertyTypeDescription
x0NumberThe x coordinate of start point.
y0NumberThe y coordinate of start point.
x1NumberThe x coordinate of end point.
y1NumberThe y coordinate of end point.

Sample Code

copy
//.js
const ctx = my.createCanvasContext('awesomeCanvas')

const grd = ctx.createLinearGradient(10, 10, 150, 10)
grd.addColorStop(0, 'yellow')
grd.addColorStop(1, 'blue')

ctx.setFillStyle(grd)
ctx.fillRect(20, 20, 250, 180)
ctx.draw()