summaryrefslogtreecommitdiff
path: root/drw/drw.go
diff options
context:
space:
mode:
Diffstat (limited to 'drw/drw.go')
-rw-r--r--drw/drw.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/drw/drw.go b/drw/drw.go
index 55a9be5..8ec05bc 100644
--- a/drw/drw.go
+++ b/drw/drw.go
@@ -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]
}