Skip to content

Commit

Permalink
Idea of the classic CA built with HECATE.
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed May 13, 2017
1 parent ace546d commit fdf8911
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/game_of_life.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from hecate import core
from hecate.init import patterns
import moire


class GameOfLife(core.CellularAutomaton):
""" The Idea of classic CA built with HECATE framework """
state = core.IntegerProperty(max_val=1)

class Topology:
lattice = core.OrthogonalLattice(dimensions=2)
neighborhood = core.MooreNeighborhood()
border = core.TorusBorder()

def emit(self):
for i in range(len(self.buffers)):
self.buffers_out[i] = self.state

def absorb(self):
neighbors_alive = core.IntegerVariable()
for i in range(len(self.buffers)):
neighbors_alive += self.buffers_in[i]
is_born = (8 >> neighbors_alive) & 1
is_sustain = (12 >> neighbors_alive) & 1
self.state = is_born | is_sustain


class GOLExperiment(core.Experiment):
""" Particular experiment, to be loaded at runtime in future """
seed = "HECATE FIRST EXPERIMENT"
dim = (960, 540)
init = patterns.BigBang(
pos=(320, 180),
size=(100, 100),
vals={
"state": patterns.RandInt(0, 1),
}
)


if __name__ == "__main__":
ca = GameOfLife(GOLExperiment)
gui = moire.GUI(runnable=ca)
gui.run()

0 comments on commit fdf8911

Please sign in to comment.