您可以将两个渐变叠加在一起:
小提琴演示 https://jsfiddle.net/epistemex/bp2rfpew/
水平渐变
从白色变为您想要使用 100% 饱和度和 50% 亮度的颜色(色相度):
var grH = ctx.createLinearGradient(0, 0, ctx.canvas.width, 0);
grH.addColorStop(0, '#fff');
grH.addColorStop(1, 'hsl(' + hue + ', 100%, 50%)');
ctx.fillStyle = grH;
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
Vertical
从底部黑色到顶部透明。
var grV = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);
grV.addColorStop(0, 'rgba(0,0,0,0)');
grV.addColorStop(1, '#000');
ctx.fillStyle = grV;
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
Result
先画水平线,然后在顶部画垂直线,结果如下:
正如在demo http://jsfiddle.net/AbdiasSoftware/ghkD9/创建一个滑块来更新色调调色板很容易。您不需要像演示中那样重新创建黑色到透明的渐变 - 只需将其缓存到屏幕外画布并在每次更新时重新使用它,因为这会给您带来更多的性能。
希望这可以帮助。