blob: 7f913fdf7092e450bb67ed1222ce5b1c85c850df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package draw
type Heatmap struct{ *Buffer }
func (b *Heatmap) Size() Box { return b.Box }
var shades = []rune(" ·░▒▒▒▒▓▓▓▓█")
var nonZeroShade = 1.0 / float64(len(shades)-1)
func (b *Heatmap) Set(y, x int, fill float64) {
if fill < 0.0 {
fill = 0.0
}
if fill > 0.0 && fill < nonZeroShade {
fill = nonZeroShade
}
if fill > 1.0 {
fill = 1.0
}
b.Buffer.Set(y, x, shades[int(fill*float64(len(shades)-1))])
}
func (b *Heatmap) Clear() { b.Fill(shades[0]) }
|