-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
52 lines (43 loc) · 1.34 KB
/
main.py
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
import numpy as np
from gpWFC.models import Model2d, Model3d, Tile
from gpWFC.observers import CLObserver
from gpWFC.propagators import CPUPropagator, CL1Propagator
from gpWFC.previews import PreviewWindow, PreviewWindow3d
from gpWFC.runners import BacktrackingRunner
if __name__ == '__main__':
import sys
if '3d' in sys.argv[1:]:
model = Model3d((4, 4, 2))
model.add(Tile((0, 1, 1, 0, 1, 0))) # all green
model.add(Tile((2, 0, 0, 2, 0, 1))) # all green
else:
model = Model2d((8, 8))
adjs = [0, 1, 2]
for adj in np.stack(np.meshgrid(adjs, adjs, adjs, adjs), -1).reshape(-1, 4):
bins = np.bincount(adj, minlength=3)
if bins[0] % 2 == 1:
continue
if bins[1] % 2 == 1:
continue
# if bins[2] % 2 == 1:
# continue
model.add(Tile(adj))
print('{} tiles:'.format(len(model.tiles)))
Propagator = CL1Propagator
if 'cpu' in sys.argv[1:]:
Propagator = CPUPropagator
runner = BacktrackingRunner(model, Observer=CLObserver, Propagator=Propagator)
if 'silent' in sys.argv[1:]:
from timeit import default_timer
start = default_timer()
status = runner.finish()
print('{} after {}s'.format(status, default_timer() - start))
else:
Preview = PreviewWindow
if '3d' in sys.argv[1:]:
Preview = PreviewWindow3d
preview = Preview(runner)
if 'render' in sys.argv[1:]:
preview.render()
else:
preview.launch()