-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.go
102 lines (83 loc) · 2.32 KB
/
command.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cli
import (
"fmt"
"github.com/jawher/mow.cli"
"github.com/nmaupu/gocube/compute"
"github.com/nmaupu/gocube/data"
"github.com/nmaupu/gocube/image"
"log"
"os"
)
const (
cubieSize = 60
)
var (
size *int
debug *bool
)
func Process(appName, appDesc, appVersion string) {
app := cli.App(appName, appDesc)
app.Spec = "[-d] [-s]"
app.Version("v version", fmt.Sprintf("%s version %s", appName, appVersion))
size = app.IntOpt("s size", 3, "Size of the cube")
debug = app.BoolOpt("d debug", false, "Enable debug mode")
app.Command("scramble", "Scramble with the given algorithm", scramble)
app.Command("reverse", "Reverse the given algorithm", reverse)
app.Command("generate", "Generate algs", generate)
app.Command("exportImg", "Generates a cube image", exportImg)
app.Command("exportPDF", "Export as a PDF", exportPDF)
app.Action = func() {
log.Fatal("Please choose a command arg !")
}
app.Run(os.Args)
}
func scramble(cmd *cli.Cmd) {
cmd.Spec = "-a"
alg := cmd.StringOpt("a alg", "", "Algorithm to use for scrambling")
cmd.Action = func() {
c := data.NewCube(*size, float64(cubieSize))
data.SetDebug(*debug)
c.Execute(data.NewAlg(*alg))
fmt.Println(c)
}
}
func reverse(cmd *cli.Cmd) {
cmd.Spec = "-a"
alg := cmd.StringOpt("a alg", "", "Algorithm to reverse")
cmd.Action = func() {
a := data.NewAlg(*alg)
fmt.Println(a.Reverse())
}
}
func generate(cmd *cli.Cmd) {
length := cmd.IntOpt("l length", 20, "Length of the algorithm to generate")
nb := cmd.IntOpt("n number", 1, "Number of algorithms to generate")
display := cmd.BoolOpt("d display", false, "Display cube status after scramble")
cmd.Action = func() {
g := compute.NewGenerator()
for i := 0; i < *nb; i++ {
alg := g.GenerateAlg(*length)
fmt.Println(alg)
if *display {
c := data.NewCube(*size, float64(cubieSize))
c.Execute(alg)
fmt.Print(c)
}
fmt.Println("-----")
}
}
}
func test3D(cmd *cli.Cmd) {
output := cmd.StringOpt("o output", "/tmp/out.png", "Output file name")
cmd.Action = func() {
c := data.NewCube(*size, float64(cubieSize))
//g := compute.NewGenerator()
//alg := g.GenerateAlg(20)
//fmt.Println(alg)
c.Execute(data.NewAlg("U' B' D2 L2 F2 R2 U B' L2 B' U B' D F2 U2 D2 B D U R2"))
imgDim := 500
ctx := c.Draw3d(imgDim)
ctx, _ = image.TrimImageWhite(ctx)
ctx.SavePNG(*output)
}
}