Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zmwangx committed Feb 14, 2017
0 parents commit 36bae16
Show file tree
Hide file tree
Showing 278 changed files with 664 additions and 0 deletions.
20 changes: 20 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017 Zhiming Wang <zmwangx@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
136 changes: 136 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
========
rule30
========

|Supported Python versions| |Docs| |License|

This project efficiently implements Stephen Wolfram's elementary cellular automata (Rule 30 being a notable example), specifically their single 1 histories. Histories can be generated in various matrix formats (including ``numpy.ndarray``) and exported as strings or images.

.. |Supported Python versions| image:: https://img.shields.io/badge/python-3.6-blue.svg?maxAge=2592000
.. |Docs| image:: https://img.shields.io/badge/docs-latest-green.svg?maxAge=2592000
:target: https://rule30.zhimingwang.org
.. |License| image:: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=2592000
:target: COPYING

.. contents::
:backlinks: top

API reference
-------------

See `rule30.zhimingwang.org <https://rule30.zhimingwang.org>`_.

Console script
--------------

::

$ rule30 --help
usage: rule30 [-h] [-n ROWS] [-r [RULE]] [-s BLOCK_SIZE] [--version] [--debug]
image

Generate images for the single 1 histories of Stephen Wolfram's elementary
cellular automata.

positional arguments:
image path to the output image (PNG format)

optional arguments:
-h, --help show this help message and exit
-n ROWS, --rows ROWS number of rows to generate; default is 256
-r [RULE], --rule [RULE]
Wolfram code of the rule (between 0 and 255); default
is 30
-s BLOCK_SIZE, --block-size BLOCK_SIZE
the size in pixels for each cell; default is 1
--version show program's version number and exit
--debug enable debug messages

See also
--------

- `Elementary Cellular Automaton <https://en.wikipedia.org/wiki/Elementary_cellular_automaton>`__, Wikipedia;
- `Rule 30 <https://en.wikipedia.org/wiki/Rule_30>`__, Wikipedia;
- `Elementary Cellular Automaton <http://mathworld.wolfram.com/ElementaryCellularAutomaton.html>`__, Wolfram MathWorld;
- `Cellular Automata <https://plato.stanford.edu/entries/cellular-automata/index.html>`__, Stanford Encyclopedia of Philosophy;
- `The 256 Rules <https://plato.stanford.edu/entries/cellular-automata/supplement.html>`__, Stanford Encyclopedia of Philosophy.

Images
------

Here are the images for some interesting rules with individual pages on `Wolfram MathWorld <http://mathworld.wolfram.com/ElementaryCellularAutomaton.html>`_. Images for all 256 rules can be found in the ``images`` directory.

`Rule 30 <http://mathworld.wolfram.com/Rule30.html>`_:

.. image:: images/rule30.png

`Rule 50 <http://mathworld.wolfram.com/Rule50.html>`_:

.. image:: images/rule50.png

`Rule 54 <http://mathworld.wolfram.com/Rule54.html>`_:

.. image:: images/rule54.png

`Rule 60 <http://mathworld.wolfram.com/Rule60.html>`_:

.. image:: images/rule60.png

`Rule 62 <http://mathworld.wolfram.com/Rule62.html>`_:

.. image:: images/rule62.png

`Rule 90 <http://mathworld.wolfram.com/Rule90.html>`_:

.. image:: images/rule90.png

`Rule 94 <http://mathworld.wolfram.com/Rule94.html>`_:

.. image:: images/rule94.png

`Rule 102 <http://mathworld.wolfram.com/Rule102.html>`_:

.. image:: images/rule102.png

`Rule 110 <http://mathworld.wolfram.com/Rule110.html>`_:

.. image:: images/rule110.png

`Rule 126 <http://mathworld.wolfram.com/Rule126.html>`_:

.. image:: images/rule126.png

`Rule 150 <http://mathworld.wolfram.com/Rule150.html>`_:

.. image:: images/rule150.png

`Rule 158 <http://mathworld.wolfram.com/Rule158.html>`_:

.. image:: images/rule158.png

`Rule 182 <http://mathworld.wolfram.com/Rule182.html>`_:

.. image:: images/rule182.png

`Rule 188 <http://mathworld.wolfram.com/Rule188.html>`_:

.. image:: images/rule188.png

`Rule 190 <http://mathworld.wolfram.com/Rule190.html>`_:

.. image:: images/rule190.png

`Rule 220 <http://mathworld.wolfram.com/Rule220.html>`_:

.. image:: images/rule220.png

`Rule 222 <http://mathworld.wolfram.com/Rule222.html>`_:

.. image:: images/rule222.png

License
-------

Copyright (c) 2017 Zhiming Wang <zmwangx@gmail.com>

This project is licensed under the MIT license. See ``COPYING`` for details.
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_build
1 change: 1 addition & 0 deletions doc/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule30.zhimingwang.org
11 changes: 11 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = rule30
SOURCEDIR = .
BUILDDIR = _build

html:

# $(O) is meant as a shortcut for $(SPHINXOPTS).
%:
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
11 changes: 11 additions & 0 deletions doc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To install dependencies for building docs::

pip install requirements.txt

To build HTML documentation::

make

To run doctest::

make doctest
46 changes: 46 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

import os
import sys

import sphinx_rtd_theme

HERE = os.path.dirname(os.path.realpath(__file__))
PROJECT_ROOT = os.path.dirname(HERE)
sys.path.insert(0, PROJECT_ROOT)

from rule30.version import __version__

project = 'rule30'
copyright = '2017, Zhiming Wang'
author = 'Zhiming Wang'
version = release = __version__

extensions = [
'sphinx.ext.autodoc',
'numpydoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
]

source_suffix = '.rst'
master_doc = 'index'
exclude_patterns = ['README.rst', '_build']
pygments_style = 'sphinx'

html_favicon = 'favicon.ico'
html_extra_path = [
'CNAME',
]

# sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# autodoc
autodoc_member_order = 'bysource'

# numpydoc
numpydoc_show_class_members = False
Binary file added doc/favicon.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
========
rule30
========

This site hosts API reference for the ``rule30`` python package. For general information, please refer to the project `README <https://github.com/zmwangx/rule30#readme>`_ on GitHub.

API reference
=============

.. toctree::
:maxdepth: 1

rule30.automaton
rule30.visualize

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
2 changes: 2 additions & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sphinx
sphinx_rtd_theme
7 changes: 7 additions & 0 deletions doc/rule30.automaton.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
======================
``rule30.automaton``
======================

.. automodule:: rule30.automaton
:members:
:undoc-members:
7 changes: 7 additions & 0 deletions doc/rule30.visualize.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
======================
``rule30.visualize``
======================

.. automodule:: rule30.visualize
:members:
:undoc-members:
1 change: 1 addition & 0 deletions images/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Images in this directory are generated with the script ``generate``. The individual image for each rule is generated with 256 rows and a block size of 1 pixel.
Binary file added images/combined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions images/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env zsh

here=$0:A:h
for rule in {0..255}; do
filename=rule$rule.png
print "Generating $filename ..." >&2
rule30 --rule $rule --rows 256 $here/$filename
done

print "Generating combined.png ..." >&2

tmpdir=$(mktemp -d -t rule30.XXXXXXX) || { print "Error: Failed to make tempdir" >&2; exit 1; }
trap 'rm -rf $tmpdir' EXIT HUP INT PIPE ALRM TERM
# Generate labels
for rule in {0..255}; do
convert -font Courier -size 511x18 -pointsize 12 -gravity south label:"Rule $rule" $tmpdir/rule$rule-label.png
done
# Copy individual images
print -l $here/rule{0..255}.png | parallel --xargs cp '{}' $tmpdir
setopt numericglobsort
print -l $tmpdir/rule*.png | convert @- -append $here/combined.png
Binary file added images/rule0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule101.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule102.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule103.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule104.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule105.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule106.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule107.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule108.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule109.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule110.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule111.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule112.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule113.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule115.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule116.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule117.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule118.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule119.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rule12.png
Binary file added images/rule120.png
Binary file added images/rule121.png
Binary file added images/rule122.png
Binary file added images/rule123.png
Binary file added images/rule124.png
Binary file added images/rule125.png
Binary file added images/rule126.png
Binary file added images/rule127.png
Binary file added images/rule128.png
Binary file added images/rule129.png
Binary file added images/rule13.png
Binary file added images/rule130.png
Binary file added images/rule131.png
Binary file added images/rule132.png
Binary file added images/rule133.png
Binary file added images/rule134.png
Binary file added images/rule135.png
Binary file added images/rule136.png
Binary file added images/rule137.png
Binary file added images/rule138.png
Binary file added images/rule139.png
Binary file added images/rule14.png
Binary file added images/rule140.png
Binary file added images/rule141.png
Binary file added images/rule142.png
Binary file added images/rule143.png
Binary file added images/rule144.png
Binary file added images/rule145.png
Binary file added images/rule146.png
Binary file added images/rule147.png
Binary file added images/rule148.png
Binary file added images/rule149.png
Binary file added images/rule15.png
Binary file added images/rule150.png
Binary file added images/rule151.png
Binary file added images/rule152.png
Binary file added images/rule153.png
Binary file added images/rule154.png
Binary file added images/rule155.png
Binary file added images/rule156.png
Binary file added images/rule157.png
Binary file added images/rule158.png
Binary file added images/rule159.png
Binary file added images/rule16.png
Binary file added images/rule160.png
Binary file added images/rule161.png
Binary file added images/rule162.png
Binary file added images/rule163.png
Binary file added images/rule164.png
Binary file added images/rule165.png
Binary file added images/rule166.png
Binary file added images/rule167.png
Binary file added images/rule168.png
Binary file added images/rule169.png
Binary file added images/rule17.png
Binary file added images/rule170.png
Binary file added images/rule171.png
Binary file added images/rule172.png
Binary file added images/rule173.png
Binary file added images/rule174.png
Binary file added images/rule175.png
Binary file added images/rule176.png
Binary file added images/rule177.png
Binary file added images/rule178.png
Binary file added images/rule179.png
Binary file added images/rule18.png
Binary file added images/rule180.png
Binary file added images/rule181.png
Binary file added images/rule182.png
Binary file added images/rule183.png
Binary file added images/rule184.png
Binary file added images/rule185.png
Binary file added images/rule186.png
Binary file added images/rule187.png
Binary file added images/rule188.png
Binary file added images/rule189.png
Binary file added images/rule19.png
Binary file added images/rule190.png
Binary file added images/rule191.png
Binary file added images/rule192.png
Binary file added images/rule193.png
Binary file added images/rule194.png
Binary file added images/rule195.png
Binary file added images/rule196.png
Binary file added images/rule197.png
Binary file added images/rule198.png
Binary file added images/rule199.png
Binary file added images/rule2.png
Binary file added images/rule20.png
Binary file added images/rule200.png
Binary file added images/rule201.png
Binary file added images/rule202.png
Binary file added images/rule203.png
Binary file added images/rule204.png
Binary file added images/rule205.png
Binary file added images/rule206.png
Binary file added images/rule207.png
Binary file added images/rule208.png
Binary file added images/rule209.png
Binary file added images/rule21.png
Binary file added images/rule210.png
Binary file added images/rule211.png
Binary file added images/rule212.png
Binary file added images/rule213.png
Binary file added images/rule214.png
Binary file added images/rule215.png
Binary file added images/rule216.png
Binary file added images/rule217.png
Binary file added images/rule218.png
Binary file added images/rule219.png
Binary file added images/rule22.png
Binary file added images/rule220.png
Binary file added images/rule221.png
Binary file added images/rule222.png
Binary file added images/rule223.png
Binary file added images/rule224.png
Binary file added images/rule225.png
Binary file added images/rule226.png
Binary file added images/rule227.png
Binary file added images/rule228.png
Binary file added images/rule229.png
Binary file added images/rule23.png
Binary file added images/rule230.png
Binary file added images/rule231.png
Binary file added images/rule232.png
Binary file added images/rule233.png
Binary file added images/rule234.png
Binary file added images/rule235.png
Binary file added images/rule236.png
Binary file added images/rule237.png
Binary file added images/rule238.png
Binary file added images/rule239.png
Binary file added images/rule24.png
Binary file added images/rule240.png
Binary file added images/rule241.png
Binary file added images/rule242.png
Binary file added images/rule243.png
Binary file added images/rule244.png
Binary file added images/rule245.png
Binary file added images/rule246.png
Binary file added images/rule247.png
Binary file added images/rule248.png
Binary file added images/rule249.png
Binary file added images/rule25.png
Binary file added images/rule250.png
Binary file added images/rule251.png
Binary file added images/rule252.png
Binary file added images/rule253.png
Binary file added images/rule254.png
Binary file added images/rule255.png
Binary file added images/rule26.png
Binary file added images/rule27.png
Binary file added images/rule28.png
Binary file added images/rule29.png
Binary file added images/rule3.png
Binary file added images/rule30.png
Binary file added images/rule31.png
Binary file added images/rule32.png
Binary file added images/rule33.png
Binary file added images/rule34.png
Binary file added images/rule35.png
Binary file added images/rule36.png
Binary file added images/rule37.png
Binary file added images/rule38.png
Binary file added images/rule39.png
Binary file added images/rule4.png
Binary file added images/rule40.png
Binary file added images/rule41.png
Binary file added images/rule42.png
Binary file added images/rule43.png
Binary file added images/rule44.png
Binary file added images/rule45.png
Binary file added images/rule46.png
Binary file added images/rule47.png
Binary file added images/rule48.png
Binary file added images/rule49.png
Binary file added images/rule5.png
Binary file added images/rule50.png
Binary file added images/rule51.png
Binary file added images/rule52.png
Binary file added images/rule53.png
Binary file added images/rule54.png
Binary file added images/rule55.png
Binary file added images/rule56.png
Binary file added images/rule57.png
Binary file added images/rule58.png
Binary file added images/rule59.png
Binary file added images/rule6.png
Binary file added images/rule60.png
Binary file added images/rule61.png
Binary file added images/rule62.png
Binary file added images/rule63.png
Binary file added images/rule64.png
Binary file added images/rule65.png
Binary file added images/rule66.png
Binary file added images/rule67.png
Binary file added images/rule68.png
Binary file added images/rule69.png
Binary file added images/rule7.png
Binary file added images/rule70.png
Binary file added images/rule71.png
Binary file added images/rule72.png
Binary file added images/rule73.png
Binary file added images/rule74.png
Binary file added images/rule75.png
Binary file added images/rule76.png
Binary file added images/rule77.png
Binary file added images/rule78.png
Binary file added images/rule79.png
Binary file added images/rule8.png
Binary file added images/rule80.png
Binary file added images/rule81.png
Binary file added images/rule82.png
Binary file added images/rule83.png
Binary file added images/rule84.png
Binary file added images/rule85.png
Binary file added images/rule86.png
Binary file added images/rule87.png
Binary file added images/rule88.png
Binary file added images/rule89.png
Binary file added images/rule9.png
Binary file added images/rule90.png
Binary file added images/rule91.png
Binary file added images/rule92.png
Binary file added images/rule93.png
Binary file added images/rule94.png
Binary file added images/rule95.png
Binary file added images/rule96.png
Binary file added images/rule97.png
Binary file added images/rule98.png
Binary file added images/rule99.png
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pillow
bitarray
3 changes: 3 additions & 0 deletions rule30/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3

from .automaton import Automaton
Loading

0 comments on commit 36bae16

Please sign in to comment.