forked from neotoolkit/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
71 lines (64 loc) · 1.71 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
package faker
import "strings"
// Color returns random color
func (f *Faker) Color() string {
return Color(
WithRand(f.cfg.rand),
WithColors(f.cfg.colors...),
)
}
// Color returns random color
//
// faker.Color(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithColors("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"), // Slice of color for RandomElement
// )
//
func Color(opts ...Option) string {
cfg := newConfig(opts...)
if len(cfg.colors) == 0 {
WithColors("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet")(cfg)
}
return RandomElement(cfg.colors, opts...)
}
// Hex returns random hex
func (f *Faker) Hex() string {
return Hex(
WithRand(f.cfg.rand),
WithHexSymbols(f.cfg.hexSymbols),
)
}
// Hex returns random hex
//
// faker.Hex(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithHexSymbols("0123456789ABCDEF"), // Hex symbols as string
// )
//
func Hex(opts ...Option) string {
var hex strings.Builder
hex.Grow(7)
hex.WriteString("#")
cfg := newConfig(opts...)
if len(cfg.hexSymbols) == 0 {
WithHexSymbols("0123456789ABCDEF")(cfg)
}
for i := 0; i < 6; i++ {
hexSymbol := Integer(0, len(cfg.hexSymbols)-1, opts...)
hex.WriteByte(cfg.hexSymbols[hexSymbol])
}
return hex.String()
}
// RGB returns random RGB
func (f *Faker) RGB() []int {
return RGB(WithRand(f.cfg.rand))
}
// RGB returns random RGB
//
// faker.RGB(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// )
//
func RGB(opts ...Option) []int {
return []int{Integer(0, 255, opts...), Integer(0, 255, opts...), Integer(0, 255, opts...)}
}