Skip to content

Commit fdf8911

Browse files
committed
Idea of the classic CA built with HECATE.
1 parent ace546d commit fdf8911

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

examples/game_of_life.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from hecate import core
2+
from hecate.init import patterns
3+
import moire
4+
5+
6+
class GameOfLife(core.CellularAutomaton):
7+
""" The Idea of classic CA built with HECATE framework """
8+
state = core.IntegerProperty(max_val=1)
9+
10+
class Topology:
11+
lattice = core.OrthogonalLattice(dimensions=2)
12+
neighborhood = core.MooreNeighborhood()
13+
border = core.TorusBorder()
14+
15+
def emit(self):
16+
for i in range(len(self.buffers)):
17+
self.buffers_out[i] = self.state
18+
19+
def absorb(self):
20+
neighbors_alive = core.IntegerVariable()
21+
for i in range(len(self.buffers)):
22+
neighbors_alive += self.buffers_in[i]
23+
is_born = (8 >> neighbors_alive) & 1
24+
is_sustain = (12 >> neighbors_alive) & 1
25+
self.state = is_born | is_sustain
26+
27+
28+
class GOLExperiment(core.Experiment):
29+
""" Particular experiment, to be loaded at runtime in future """
30+
seed = "HECATE FIRST EXPERIMENT"
31+
dim = (960, 540)
32+
init = patterns.BigBang(
33+
pos=(320, 180),
34+
size=(100, 100),
35+
vals={
36+
"state": patterns.RandInt(0, 1),
37+
}
38+
)
39+
40+
41+
if __name__ == "__main__":
42+
ca = GameOfLife(GOLExperiment)
43+
gui = moire.GUI(runnable=ca)
44+
gui.run()

0 commit comments

Comments
 (0)