add radial gradient color fun

This commit is contained in:
jiaming 2018-12-15 19:16:31 +08:00
parent 55ab59fa4f
commit f45f7f742d
1 changed files with 17 additions and 0 deletions

View File

@ -147,6 +147,22 @@ export function getLinearGradientColor (ctx, begin, end, color) {
return linearGradientColor
}
export function getRadialGradientColor (ctx, origin, begin = 0, end = 100, color) {
if (!ctx || !origin || !color.length) return
let colors = color
typeof colors === 'string' && (colors = [color, color])
const radialGradientColor = ctx.createRadialGradient(...origin, begin, ...origin, end)
const colorGap = 1 / (colors.length - 1)
colors.forEach((c, i) => radialGradientColor.addColorStop(colorGap * i, c))
return radialGradientColor
}
export function getCircleRadianPoint (x, y, radius, radian) {
const { sin, cos } = Math
@ -163,6 +179,7 @@ const canvas = {
drawBezierCurveLinePath,
drawPoints,
getLinearGradientColor,
getRadialGradientColor,
getCircleRadianPoint
}