These 2 commands produce slightly different gradients - based on the w3schools help, I had no idea why.
var grd = ctx.createLinearGradient(0, 0, 10, canvas.height-10); var grd = ctx.createLinearGradient(0, 0, 0, canvas.height-10); |
var grd = ctx.createLinearGradient(0, 0, 10, canvas.height-delta_x); grd.addColorStop(0, "white"); grd.addColorStop(0.06, "white");// required to get white on top grd.addColorStop(1, "black"); ctx.fillStyle = grd; ctx.fillRect(x, 0, delta_x, canvas.height-delta_x); |
Examples
|
|
|
In this example, the gradient sets both the width and height.
The colors of the 2 corners are 0xFEFEFE and 0x030303. | ||
|
In this example, the gradient sets both the width and height
and gradient start point is (2,2) and the end point is six less than the canvas size.
The colors of the 2 corners are 0xFFFFFF and 0x000000 - exactly what is wanted. When the starting point was (1,1) and the endpoint was only one or two less than the canvas size, the results were fairly poor. | |||
|
Analysis
context.createLinearGradient(x0, y0, x1, y1); |
An additional source