hbspbar

[WIP] bspwm status bar
git clone https://hhvn.uk/hbspbar
git clone git://hhvn.uk/hbspbar
Log | Files | Refs

commit 0f4869662c6ea6f5d4b976d5ff95b12d2f1cf198
parent d5ffccc1b4499e01ebb8d727c4651856894e154f
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 19 Nov 2023 15:35:56 +0000

Variadic drw.Blend

Diffstat:
Mdrw/drw.go | 25+++++++++++++------------
Mstatus/00-status.go | 4++--
2 files changed, 15 insertions(+), 14 deletions(-)

diff --git 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] } diff --git a/status/00-status.go b/status/00-status.go @@ -88,11 +88,11 @@ func sleep(s int) { } func blendGYR(percent int) color.Color { - return drw.Blend3(config.Green, config.Yellow, config.Red, percent) + return drw.Blend(percent, config.Green, config.Yellow, config.Red) } func blendBg(c color.Color) color.Color { - return drw.Blend(c, config.Status, 75) + return drw.Blend(75, c, config.Status) } func (s *status) furthest(x int) {