-
Notifications
You must be signed in to change notification settings - Fork 1
/
images.go
62 lines (51 loc) · 1.5 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bytes"
"github.com/biessek/golang-ico"
"image"
"image/color"
)
var img = image.NewRGBA(image.Rect(0, 0, 32, 32))
// HLine draws a horizontal line
func HLine(x1, y, x2 int, col color.Color) {
for ; x1 <= x2; x1++ {
img.Set(x1, y, col)
}
}
// VLine draws a veritcal line
func VLine(x, y1, y2 int, col color.Color) {
for ; y1 <= y2; y1++ {
img.Set(x, y1, col)
}
}
// Rect draws a rectangle utilizing HLine() and VLine()
func Rect(x1, y1, x2, y2 int, col color.Color) {
HLine(x1, y1, x2, col)
HLine(x1, y2, x2, col)
VLine(x1, y1, y2, col)
VLine(x2, y1, y2, col)
}
func FillRect(x1, y1, x2, y2 int, col color.Color) {
for x := x1; x <= x2; x++ {
for y := y1; y <= y2; y++ {
img.Set(x, y, col)
}
}
}
func bar_y(usage float32) int {
return int(0.5 + 32*(1.0-usage))
}
func gen_img(ram_usage, phys_usage, cpu_usage float32) {
img = image.NewRGBA(image.Rect(0, 0, 32, 32))
Rect(0, 0, 32, 32, color.RGBA{0, 0, 0, 255})
FillRect(1, 1, 31, 31, color.RGBA{255, 255, 255, 255})
FillRect(1, bar_y(ram_usage), 10, 32, color.RGBA{255, 0, 0, 255})
FillRect(11, bar_y(phys_usage), 21, 32, color.RGBA{0, 255, 0, 255})
FillRect(21, bar_y(cpu_usage), 31, 32, color.RGBA{0, 0, 255, 255})
}
func gen_image_data(ram_usage, phys_usage, cpu_usage float32) []byte {
gen_img(ram_usage, phys_usage, cpu_usage)
var imageBuf bytes.Buffer
ico.Encode(&imageBuf, img)
return imageBuf.Bytes()
}