/
color.go
82 lines (74 loc) · 1.22 KB
/
color.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package videosource
import (
"image/color"
"strings"
)
type ColorThickness struct {
Color Color
Thickness int
}
func NewColorThickness(color string, thickness int) *ColorThickness {
c := &ColorThickness{
Color: StringToColor(color),
Thickness: thickness,
}
return c
}
// Color represents a color
type Color int
// Color Constants
const (
Blue Color = iota
Purple
Green
Red
White
)
// StringToColor returns a Color
func StringToColor(name string) Color {
s := strings.ToLower(name)
switch s {
case "blue":
return Blue
case "purple":
return Purple
case "green":
return Green
case "red":
return Red
case "white":
return White
}
return White
}
func (c Color) String() string {
switch c {
case Blue:
return "blue"
case Purple:
return "purple"
case Green:
return "green"
case Red:
return "red"
case White:
return "white"
}
return ""
}
// GetRGBA returns the color rgba
func (c Color) GetRGBA() color.RGBA {
switch c {
case Blue:
return color.RGBA{0, 0, 255, 0}
case Purple:
return color.RGBA{255, 0, 255, 0}
case Green:
return color.RGBA{0, 255, 0, 0}
case Red:
return color.RGBA{255, 0, 0, 0}
case White:
return color.RGBA{0, 0, 0, 0}
}
return color.RGBA{0, 0, 0, 0}
}