-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-brocade.go
70 lines (57 loc) · 1.47 KB
/
go-brocade.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
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"strings"
"time"
svg "github.com/ajstarks/svgo"
"github.com/cheshire137/go-brocade/pkg/models"
"github.com/cheshire137/go-brocade/pkg/patterns"
)
func main() {
rand.Seed(time.Now().UnixNano())
options, err := models.ParseOptions()
if err != nil {
fmt.Println("Could not parse options: " + err.Error())
os.Exit(1)
return
}
if options.ListPatterns {
fmt.Print("Patterns: ")
patternNames := patterns.PatternNames()
fmt.Printf("%s\n", strings.Join(patternNames, ", "))
os.Exit(0)
return
}
if options.InteractiveMode {
fmt.Print("Output path: ")
fmt.Scanln(&options.OutPath)
}
if len(options.OutPath) < 1 {
fmt.Printf("Usage: %s [options]\n\n", os.Args[0])
flag.PrintDefaults()
os.Exit(0)
return
}
outFile, err := os.Create(options.OutPath)
if err != nil {
fmt.Println("Could not create SVG file: " + err.Error())
os.Exit(1)
return
}
fmt.Println("Using options:")
fmt.Println(options.String())
canvas := svg.New(outFile)
canvas.Start(options.Width, options.Height)
canvas.Rect(0, 0, options.Width, options.Height, fmt.Sprintf("fill:%s", options.Background))
for _, config := range options.PatternConfigs {
pattern := config.Pattern
pattern.DefinePattern(options.Width, options.Height, canvas)
style := pattern.Style(config.Color, config.Xoffset, config.Yoffset)
canvas.Rect(0, 0, options.Width, options.Height, style)
}
canvas.End()
fmt.Printf("Wrote %s\n", options.OutPath)
}