Skip to main content

Engine for prototyping and playing with cellular automata

Project description

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!)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tomato-engine-2.0.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tomato_engine-2.0.0-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file tomato-engine-2.0.0.tar.gz.

File metadata

  • Download URL: tomato-engine-2.0.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for tomato-engine-2.0.0.tar.gz
Algorithm Hash digest
SHA256 93481c21cf33de689732894ab7b961ffad6003459abc0d49f93be4d7dd4be9fd
MD5 903db767b93ef2197b4e3921c09fe8bb
BLAKE2b-256 cdbb7f0743fbc641cb3feedac6f8569562a308f1d8b5f4f4c3f8230d53ee1bfd

See more details on using hashes here.

File details

Details for the file tomato_engine-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: tomato_engine-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for tomato_engine-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31e8ceecb3086e4cc41b46fb4afd48bf82da8e4e051fbf156e91d8156b91b468
MD5 234ef7bb724199b4582d8da53286326c
BLAKE2b-256 b750885063e120000f08451c3ada3b2353d3fd801b7801a3642bc3fa17dba30d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page