-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (49 loc) · 1.54 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
63
64
65
66
67
package main
import (
"fmt"
"gopkg.in/alecthomas/kingpin.v2"
"joshtompkins.com/elementary-automata/automata"
"joshtompkins.com/elementary-automata/evaluators"
"joshtompkins.com/elementary-automata/generation"
"joshtompkins.com/elementary-automata/renderers"
"joshtompkins.com/elementary-automata/rules"
)
var (
size = kingpin.Flag("size", "Size of each generation").Short('s').Default("1000").Int()
gens = kingpin.Flag("generations", "Number of generations to simulate").Short('g').Default("1000").Int()
scale = kingpin.Flag("scale", "Size of each cell in the output in pixels").Default("1").Int()
centered = kingpin.Flag("center", "Center the initial generation").Short('c').Bool()
rule = kingpin.Arg("rule", "Wolfram rule to use").Required().Int()
file = kingpin.Arg("file", "Path to output PNG").Required().String()
)
func main() {
kingpin.Version("0.1")
kingpin.Parse()
fmt.Print("\n🤖 Reading configuration\t")
r, _ := rules.Get(*rule)
var initial generation.Generation
if *centered {
initial = generation.NewFromCenter(*size)
} else {
initial = generation.NewFromRandom(*size)
}
fmt.Println("✅")
fmt.Print("🤖 Spinning up an automata\t")
a := automata.New(
initial,
evaluators.NewRuleEvaluator(r),
renderers.NewPngRenderer(&renderers.RenderOptions{
File: *file,
Scale: *scale,
}),
)
fmt.Println("✅")
fmt.Print("🤖 Evaluating rules\t\t")
for i := 1; i <= *size; i++ {
a.Step()
}
fmt.Println("✅")
fmt.Print("🤖 Rendering image\t\t")
a.Render()
fmt.Println("✅\n")
}