1、辐射渐变
<style>
canvas {
width: 500px;
height: 300px;
border: 1px solid;
}
</style>
</head>
<body>
<canvas id="can" width="500px" height="300px"></canvas>
<script>
var canvas = document.getElementById("can");
var ctx = canvas.getContext("2d");
ctx.beginPath();
var bg = ctx.createRadialGradient(100,100,0,100,100,100);// 参数:第一个点的坐标和半径,第二个点的坐标和半径:起始圆和结束圆
/* var bg = ctx.createRadialGradient(50,50,20,100,100,100);//圆心不在同一个 */
/* var bg = ctx.createRadialGradient(20,20,10,100,100,50);//起始圆小于结束圆并且相离 */
bg.addColorStop(0,"red");
bg.addColorStop(0.5,"green");
bg.addColorStop(1,"blue");
ctx.fillStyle = bg;
ctx.fillRect(0,0,200,200);
</script>
</body>
2、模糊光圈
<style>
canvas {
width: 500px;
height: 300px;
border: 1px solid;
}
</style>
</head>
<body>
<canvas id="can" width="500px" height="300px"></canvas>
<script>
var canvas = document.getElementById("can");
var ctx = canvas.getContext("2d");
ctx.beginPath();
//模糊光圈
var bg = ctx.createRadialGradient(100,100,30,100,100,100);
bg.addColorStop(0,"white");
bg.addColorStop(0.5,"black");
bg.addColorStop(1,"white");
ctx.fillStyle = bg;
ctx.fillRect(0,0,200,200);
</script>
</body>