diff options
Diffstat (limited to 'pkg/draw/heatmap.go')
-rw-r--r-- | pkg/draw/heatmap.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/draw/heatmap.go b/pkg/draw/heatmap.go new file mode 100644 index 0000000..7f913fd --- /dev/null +++ b/pkg/draw/heatmap.go @@ -0,0 +1,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]) } |