Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Elementary cellular automata in Python

Project Description

This is a Python implementation of elementary cellular automata.

Installation

Pip

pip install rule_n

Manual

Download rule_n.py and put it somewhere in your Python path.

Usage

import rule_n

rule_110 = rule_n.RuleN(110)
rule_30 = rule_n.RuleN(30)
rule_184 = rule_n.RuleN(184)  # Works with anything from 1 to 255
rule_110 = rule_n.RuleN()  # Default rule is 110, as that is the most common
from rule_n import rule_90   # Shorthand for rule_90 = rule_n.RuleN(90)
                             # Works with 110, 30, 90, 184
# You can also specify a list of rules
rule_110 = rule_n.RuleN([False, True, True, False, True, True, True, False])
# Or a string that summarizes the rule
rule_110 = rule_n.RuleN("01101110")
# See <https://en.wikipedia.org/wiki/Rule_110#Definition>
# You can also have a finite canvas
rule_110_finite_canvas = rule_n.RuleN(110, canvas_size=5)
# A canvas is finite if its size is over 0

data = rule_110.process([True, False, True])
len(data) == 5  # because a False is added to both sides
data == [True, True, True, True, False]

data_2 = rule_110.process([1, 0, 1])  # You can use any data type, as long
data == data_2                        # as the boolean values of these are
                                      # correct
                                      # Return values are always in boolean

# With a finite canvas, the output is always as big as the canvas
data = rule_110_finite_canvas.process([0, 0, 0, 0, 1])
data == [False, False, False, True, True]

data_3 = rule_110([True, False, True])  # Shorthand for
                                        # rule_110.process(state)
data == data_3

i = 0
for x in rule_110.iterate([1, 0, 1]):  # Repeatedly process a state
    print x
    i += 1
    if i == 10:
        break  # Please do this
# Note: Iteration on an infinte canvas seems to have some problems
# I recommend using a finite canvas
for x in rule_110_finite_canvas.iterate([0, 0, 0, 0, 1]):
    print x
    # This breaks automatically if the current state is equal to the
    # previous, which will probably happen at some point on a finite canvas
Release History

Release History

This version
History Node

0.2.1

History Node

0.2

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
rule_n-0.2.1-py2.py3-none-any.whl (7.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel May 16, 2016
rule_n-0.2.1.tar.gz (17.8 kB) Copy SHA256 Checksum SHA256 Source May 16, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting