diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-19 13:29:12 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-19 13:30:04 +0000 |
| commit | 3ad7ace9c1cc88b4ec4eed8c4eee801e1f659110 (patch) | |
| tree | fb6fe064518626fd44783ab65a1f1c4acc8b1cb3 | |
| parent | 19781aeb974bd20c421a6b4677ffab348df8faf9 (diff) | |
Color blending
| -rw-r--r-- | drw/drw.go | 18 | ||||
| -rw-r--r-- | drw/x.go | 18 | ||||
| -rw-r--r-- | go.mod | 1 | ||||
| -rw-r--r-- | go.sum | 2 |
4 files changed, 39 insertions, 0 deletions
@@ -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()) +} @@ -77,6 +77,24 @@ func int2rgb(argb uint32) (color.RGBA) { A: uint8((argb & 0xff000000) >> 24) } } +func rgb2int(c color.Color) uint32 { + r, g, b, a := c.RGBA() + + r /= 256 + g /= 256 + b /= 256 + a /= 256 + + var ret uint32 = 0 + + ret |= (a << 24) + ret |= (r << 16) + ret |= (g << 8) + ret |= b + + return ret +} + type Window struct { id xproto.Window } @@ -7,4 +7,5 @@ require ( github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect github.com/jezek/xgb v1.1.0 // indirect github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect ) @@ -6,3 +6,5 @@ github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk= github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0 h1:Pf/0BAbppEOq4azPH6fnvUX2dycAwZdGkdxFn25j44c= github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0/go.mod h1:AHecLyFNy6AN9f/+0AH/h1MI7X1+JL5bmCz4XlVZk7Y= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |