const drawGradientCirlce1 = (ctx, points) => {
ctx.save()
// 定义渐变
let gradient = ctx.createLinearGradient(points[0].x, points[0].y, points[points.length - 1].x, points[points.length - 1].y) //根据给定的两坐标所构成的线段创建一个线性渐变
gradient.addColorStop(0, 'blue')
gradient.addColorStop(1, '#81DDFF')
// 绘制每个圆并应用渐变颜色
for (let i = 0; i < points.length; i++) {
drawPoint(ctx, points[i].x, points[i].y, points[i].r, gradient)
}
ctx.restore()
}
// cx,cy 圆的中心 r圆的半径
const drawPoint = (ctx, cx, cy, r, color = '#FFC237') => {
// 保存画笔状态
ctx.save()
ctx.lineWidth = 2
ctx.moveTo(cx, cy)
ctx.beginPath()
// 画弧 圆心 半径 起始角度,终结角度
ctx.arc(cx, cy, r, 0, Math.PI * 2)
ctx.fillStyle = color //填充颜色
ctx.fill() //闭合圆形路径
ctx.strokeStyle = color //描边
ctx.stroke()
ctx.closePath()
// 还原画笔状态
ctx.restore()
}
let humanCirclePoints2 = [
{x: 120, y: 120, r: 10},
{x: 130, y: 130, r: 10},
{x: 140, y: 140, r: 10},
{x: 150, y: 150, r: 10},
{x: 160, y: 160, r: 10},
]
07-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交