Debian Codegraph @

vendor/github.com/lucasb-eyer/go-colorful/happy_palettegen.go

raw
1 package colorful
2
3 // Uses the HSV color space to generate colors with similar S,V but distributed
4 // evenly along their Hue. This is fast but not always pretty.
5 // If you've got time to spare, use Lab (the non-fast below).
6 func FastHappyPaletteWithRand(colorsCount int, rand RandInterface) (colors []Color) {
7 colors = make([]Color, colorsCount)
8
9 for i := 0; i < colorsCount; i++ {
10 colors[i] = Hsv(float64(i)*(360.0/float64(colorsCount)), 0.8+rand.Float64()*0.2, 0.65+rand.Float64()*0.2)
11 }
12 return
13 }
14
15 func FastHappyPalette(colorsCount int) (colors []Color) {
16 return FastHappyPaletteWithRand(colorsCount, getDefaultGlobalRand())
17 }
18
19 func HappyPaletteWithRand(colorsCount int, rand RandInterface) ([]Color, error) {
20 pimpy := func(l, a, b float64) bool {
21 _, c, _ := LabToHcl(l, a, b)
22 return 0.3 <= c && 0.4 <= l && l <= 0.8
23 }
24 return SoftPaletteExWithRand(colorsCount, SoftPaletteSettings{pimpy, 50, true}, rand)
25 }
26
27 func HappyPalette(colorsCount int) ([]Color, error) {
28 return HappyPaletteWithRand(colorsCount, getDefaultGlobalRand())
29 }