-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
40 lines (36 loc) · 734 Bytes
/
util.go
File metadata and controls
40 lines (36 loc) · 734 Bytes
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
package framebuf
import (
"crypto/rand"
"fmt"
"image/color"
"strings"
)
func randBytes() []byte {
buf := make([]byte, 1024)
rand.Read(buf)
return buf
}
// Colour will turn RGB values into a Go-compatible colour
func Colour(r, g, b uint8) color.Color {
return color.RGBA{
R: r, G: g, B: b, A: 255,
}
}
// HexColour will parse a HTML-style hexcode into a Go-compatible colour
func HexColour(s string) (c color.RGBA) {
s = strings.TrimPrefix(s, "#")
c.A = 0xff
switch len(s) {
case 6:
_, _ = fmt.Sscanf(s, "%02x%02x%02x", &c.R, &c.G, &c.B)
case 3:
_, _ = fmt.Sscanf(s, "%1x%1x%1x", &c.R, &c.G, &c.B)
// Double the hex digits:
c.R *= 17
c.G *= 17
c.B *= 17
default:
panic("invalid length")
}
return
}