diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-19 15:35:56 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-19 15:35:56 +0000 |
| commit | 0f4869662c6ea6f5d4b976d5ff95b12d2f1cf198 (patch) | |
| tree | c26e95d65cbcaaf076e7b6d9d0f1c937a3e693b7 /drw/drw.go | |
| parent | d5ffccc1b4499e01ebb8d727c4651856894e154f (diff) | |
Variadic drw.Blend
Diffstat (limited to 'drw/drw.go')
| -rw-r--r-- | drw/drw.go | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -53,19 +53,20 @@ func AddImg(dst *image.RGBA, x, w int, src *image.RGBA) { draw.Draw(dst, r, src, image.Pt(0,0), draw.Src) } -func Blend3(a, b, c color.Color, percent int) color.Color { - if percent <= 50 { - return Blend(a, b, percent * 2) - } else { - return Blend(b, c, (percent - 50) * 2) - } -} +func Blend(percent int, cols ...color.Color) color.Color { + step := 100 / (len(cols) - 1) + + if percent < 0 { percent = 0 } + if percent > 100 { percent = 100 } -// Conversion hell, I know -func Blend(a, b color.Color, percent int) color.Color { - ac, _ := col.MakeColor(a) - bc, _ := col.MakeColor(b) + for i, cstep := 1, step; i < len(cols); i, cstep = i + 1, cstep + step { + if percent >= cstep - step && percent <= cstep { + a, _ := col.MakeColor(cols[i - 1]) + b, _ := col.MakeColor(cols[i]) + return a.BlendHcl(b, float64(percent) / 100).Clamped() + } + } - return color.Color(ac.BlendHcl(bc, float64(percent) / 100).Clamped()) + return cols[len(cols) - 1] } |