From 66b0b3e1343fb8f42972c35b4a393378df6ebed3 Mon Sep 17 00:00:00 2001 From: rkfg Date: Tue, 13 Sep 2022 02:37:53 +0300 Subject: [PATCH] Better color gradients for channel age --- ui/views/views.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ui/views/views.go b/ui/views/views.go index fdc72d6..bfde012 100644 --- a/ui/views/views.go +++ b/ui/views/views.go @@ -132,16 +132,28 @@ func FormatAge(age uint32) string { return fmt.Sprintf("%02dy%02dm%02dd", age/52596, (age%52596)/4383, (age%4383)/144) } +func interp(a, b [3]float64, r float64) (result [3]float64) { + result[0] = a[0] + (b[0]-a[0])*r + result[1] = a[1] + (b[1]-a[1])*r + result[2] = a[2] + (b[2]-a[2])*r + return +} + func ColorizeAge(age uint32, text string, opts ...lntcolor.Option) string { - s := 1.0 - l := 0.5 - if age < 52596 { - s = float64(age) / 52596 + ageColors := [][3]float64{ + {120, 0.9, 0.9}, + {60, 0.9, 0.6}, + {22, 1, 0.5}, } - if age < 8766 { // increase brightness slightly for 16 color terminals or else it renders as black - l = 0.66 + cur := [3]float64{} + if age < 26298 { + cur = interp(ageColors[0], ageColors[1], float64(age)/26298) + } else if age < 52596 { + cur = interp(ageColors[1], ageColors[2], float64(age-26298)/26298) + } else { + cur = ageColors[2] } - val := color.HSL(22./360, s, l).C256().Value() + val := color.HSL(cur[0]/360, cur[1], cur[2]).C256().Value() c := color.S256(val) options := lntcolor.NewOptions(opts) if options.Bold {