diff options
Diffstat (limited to 'drw')
| -rw-r--r-- | drw/drw.go | 18 | ||||
| -rw-r--r-- | drw/x.go | 18 |
2 files changed, 36 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 } |