/
main.go
62 lines (50 loc) · 1.06 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/Burmuley/life/lifeform"
"github.com/Burmuley/life/lifeform/simplecell"
"github.com/Burmuley/life/ui"
"github.com/Burmuley/life/world"
"github.com/Burmuley/life/world/convey"
)
func fillWorld(w world.Explorer) {
rand.Seed(time.Now().UnixNano())
n := 200000
maxR, maxC := w.Size()
for col := 0; col < maxC; col++ {
for row := 0; row < maxR; row++ {
l := world.Location{
Row: row,
Col: col,
}
rnd := rand.Intn(n)
state := lifeform.DEAD
if rnd > n/2 {
state = lifeform.ALIVE
}
w.SetLife(simplecell.New(state), l)
}
}
}
var cmdui string
func main() {
var appUi ui.UI
flag.StringVar(&cmdui, "ui", "console", "choose UI: 'console' or 'gui'")
flag.Parse()
conveyWorld := convey.NewFilled(30, 50, fillWorld)
fabric := ui.NewFabric()
switch cmdui {
case "console":
appUi = fabric.Get("Console")
case "gui":
appUi = fabric.Get("Fyne")
default:
log.Fatal(fmt.Sprintf("Unknown UI provided: %s", cmdui))
}
appUi.SetWorld(conveyWorld)
appUi.Run()
}