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.
Property | Type | Description |
x0 | Number | The x coordinate of start point. |
y0 | Number | The y coordinate of start point. |
x1 | Number | The x coordinate of end point. |
y1 | Number | The 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()