-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathgradientgen.go
36 lines (30 loc) · 1.09 KB
/
gradientgen.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
package main
import "flag"
import "log"
import "strconv"
// same thing as MustParseHex but for float parsing
func MustParseFloatZeroOne(s string) float64 {
f, err := strconv.ParseFloat(s, 64)
if err != nil {
log.Fatalf("Invalid keypoint position: %v: %v\n", s, err.Error())
}
if f < 0.0 || 1.0 < f {
log.Fatalf("Invalid keypoint position: %v: keypoints must lie within 0.0 and 1.0\n", s)
}
return f
}
func main() {
pname := flag.String("name", "unnamed", "The name of the colorscheme.")
pw := flag.Uint64("w", 40, "Width of the pictures of the colorscheme.")
ph := flag.Uint64("h", 1024, "Height (number of levels) of the colorscheme.")
flag.Parse()
if flag.NArg() < 2*2 || flag.NArg() % 2 != 0 {
flag.Usage()
log.Fatal("Need at least two gradient keypoints!")
}
keypoints := GradientTable{}
for i := 0 ; i < flag.NArg() ; i += 2 {
keypoints = append(keypoints, GradientTableEntry{MustParseHex(flag.Arg(i)), MustParseFloatZeroOne(flag.Arg(i+1))})
}
CreateColorschemes(keypoints, *pname, int(*pw), int(*ph))
}