1package main 2 3import "strings" 4 5var colorPalette = []string{ 6 `"#f44336"`, `"#9c27b0"`, `"#3f51b5"`, `"#03a9f4"`, `"#009688"`, `"#8bc34a"`, `"#ffeb3b"`, `"#ff9800"`, 7 `"#795548"`, `"#607d8b"`, `"#e91e63"`, `"#673ab7"`, `"#2196f3"`, `"#00bcd4"`, `"#4caf50"`, `"#cddc39"`, 8 `"#ffc107"`, `"#ff5722"`, `"#9e9e9e"`} 9 10var colorI = 0 11 12// Reset restarts the palette iterator. Following Reset(), invoking Next() returns the first color in the palette. 13func colorReset() { 14 colorI = 0 15} 16 17// Next iterates through the color palette. 18func colorNext() string { 19 result := colorPalette[colorI] 20 colorI++ 21 if colorI > len(colorPalette)-1 { 22 colorI = 0 23 } 24 25 return result 26} 27 28func colorIndex(i int) string { 29 return colorPalette[i%len(colorPalette)] 30} 31 32// FirstN returns a comma-separated string of the first n colors in the palette. 33func colorFirstN(n int) string { 34 k := 0 35 var cs []string 36 for j := 0; j < n; j++ { 37 cs = append(cs, colorPalette[k]) 38 k++ 39 if k > len(colorPalette)-1 { 40 k = 0 41 } 42 } 43 return strings.Join(cs, ",") 44} 45 46func colorRepeat(i, n int) string { 47 return strings.Repeat(colorIndex(i)+",", n) 48} 49