5
1
Fork
You've already forked tomato-engine
0
Engine for prototyping and playing with cellular automata
  • Python 98.5%
  • Scheme 1.5%
Find a file
2024年02月04日 16:14:54 -03:00
src Config line length to 79 2024年02月04日 16:14:54 -03:00
.gitignore Added .gitignore 2021年07月01日 00:53:01 -03:00
.pylintrc Added pylintrc 2022年10月17日 15:09:59 -03:00
LICENSE Initial commit 2021年07月01日 00:49:32 -03:00
manifest.scm Fixed license entry for python-tomato-engine in manifest.scm 2023年09月26日 23:17:21 -03:00
pyproject.toml Config line length to 79 2024年02月04日 16:14:54 -03:00
README.md Linted the board.py and slightly changed the README 2022年10月17日 16:08:24 -03:00
setup.cfg Incremented major version number 2023年06月29日 15:11:21 -03:00
setup.py Incremented major version number 2023年06月29日 15:11:21 -03:00

tomato-engine

Engine for prototyping and playing with cellular automata.

Motivation

Tomato-engine aims to be an easy to use, extensible and hackable framework for running cellular automata simulations controlled via Python.

It handles much of the overhead involved in getting a simple realtime visualization of the cellular automata to run, while providing an object oriented interface through which the user can easily craft their own cellular automata ruleset, and leave tomato-engine to handle all the rest.

Installation

pip3 install tomato-engine

Example and basic usage

New rules are implemented on a Python module, which must contain the class Cell, which inherits from CellTemplate and specifies how the cell should update on each iteration through the function Cell.update.

For simple, binary totalistic automata rulesets such as the Conway's Game of Life, the class can be as simple as this:

from tomato.classes import cell
class Cell(cell.CellTemplate):
 def update(self, state_matrix):
 self.state_matrix = state_matrix
 # Dead cell
 if self.value == 0:
 if self.live_neighbors == 3:
 self.value = 1
 else:
 self.value = 0
 # Live cell
 else:
 if self.live_neighbors in (2, 3):
 self.value = 1
 else:
 self.value = 0
 @property
 def neighbors(self):
 return self.moore_neighborhood
 @property
 def live_neighbors(self):
 return sum(self.neighbors)

This module is then imported and passed to the Board class, which provides the user interface.

import tomato as tt
from tomato.functions import utils
from my_rules import game_of_life as rule
# Board dimensions in number of automata in each direction
board_dimensions = (100, 100)
# Scaling factor for the board in the display
cell_size = 4
# Convenience function for generating a numpy matrix
# of random binary values
state_matrix = utils.random_matrix(board_dimensions, 2)
board = tt.Board(rule, cell_size=cell_size)
# Opens the simulation window
board.start(state_matrix)

Also check out our repository of rulesets made for tomato-engine.

More information on how to craft new rulesets and interact with your simulation can be found on our readthedocs: (coming soon!)