From 3ad7ace9c1cc88b4ec4eed8c4eee801e1f659110 Mon Sep 17 00:00:00 2001 From: hhvn Date: Sun, 19 Nov 2023 13:29:12 +0000 Subject: Color blending --- drw/drw.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'drw/drw.go') diff --git a/drw/drw.go b/drw/drw.go index a0b3579..e5a16c2 100644 --- a/drw/drw.go +++ b/drw/drw.go @@ -7,6 +7,7 @@ import ( "hhvn.uk/hbspbar/config" "github.com/jezek/xgbutil/xgraphics" + col "github.com/lucasb-eyer/go-colorful" "github.com/BurntSushi/freetype-go/freetype" ) @@ -52,3 +53,20 @@ func AddImg(dst *image.RGBA, x, w int, src *image.RGBA) { r := image.Rect(x, 0, x + w, int(config.H)) draw.Draw(dst, r, src, image.Pt(0,0), draw.Src) } + +func Blend3(a, b, c uint32, percent int) uint32 { + if percent <= 50 { + return Blend(a, b, percent * 2) + } else { + return Blend(b, c, (percent - 50) * 2) + } +} + +// Conversion hell, I know +func Blend(a, b uint32, percent int) uint32 { + ac, _ := col.MakeColor(int2rgb(a)) + bc, _ := col.MakeColor(int2rgb(b)) + + + return rgb2int(ac.BlendHcl(bc, float64(percent) / 100).Clamped()) +} -- cgit v1.2.3