...
1
2
3
4
5 package palette
6
7 import (
8 "image/color"
9 )
10
11
12 func Reverse(c ColorMap) ColorMap {
13 return reverse{ColorMap: c}
14 }
15
16
17
18 type reverse struct {
19 ColorMap
20 }
21
22
23 func (r reverse) At(v float64) (color.Color, error) {
24 return r.ColorMap.At(r.Max() - (v - r.Min()))
25 }
26
27
28 func (r reverse) Palette(colors int) Palette {
29 c := r.ColorMap.Palette(colors).Colors()
30 c2 := make([]color.Color, len(c))
31 for i, j := 0, len(c)-1; i < j; i, j = i+1, j-1 {
32 c2[i], c2[j] = c[j], c[i]
33 }
34 return palette(c2)
35 }
36
View as plain text