-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolor.go
More file actions
77 lines (67 loc) · 1.83 KB
/
color.go
File metadata and controls
77 lines (67 loc) · 1.83 KB
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
package gofaker
import (
"math/rand"
)
// Color will generate a random color string
func Color() string {
return getRandValue([]string{"color", "full"})
}
// SafeColor will generate a random safe color string
func SafeColor() string {
return getRandValue([]string{"color", "safe"})
}
// HexColor will generate a random hexadecimal color string
func HexColor() string {
color := make([]byte, 6)
hashQuestion := []byte("?#")
for i := 0; i < 6; i++ {
color[i] = hashQuestion[rand.Intn(2)]
}
return "#" + replaceWithHexLetters(replaceWithNumbers(string(color)))
}
// RGBColor will generate a random int slice color
func RGBColor() []int {
return []int{randIntRange(0, 255), randIntRange(0, 255), randIntRange(0, 255)}
}
func addColorLookup() {
AddFuncLookup("color", Info{
Display: "Color",
Category: "color",
Description: "Random color",
Example: "MediumOrchid",
Output: "string",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return Color(), nil
},
})
AddFuncLookup("safecolor", Info{
Display: "Safe Color",
Category: "color",
Description: "Random safe color",
Example: "black",
Output: "string",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return SafeColor(), nil
},
})
AddFuncLookup("hexcolor", Info{
Display: "Hex Color",
Category: "color",
Description: "Random hex color",
Example: "#a99fb4",
Output: "string",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return HexColor(), nil
},
})
AddFuncLookup("rgbcolor", Info{
Display: "RGB Color",
Category: "color",
Description: "Random rgb color",
Example: "[152 23 53]",
Output: "string",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return RGBColor(), nil
},
})
}