• Stars
    star
    172
  • Rank 219,856 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Python implementation of Conway's game of life and other cellular automata, computed using numpy.fft

Alt text

Fast Python implementation of Conway's game of life and other cellular automata

Running

Requires Python 2.7+ or Python 3+ with Numpy and Matplotlib.

To run Game of Life:

$ python conway.py

To run Replicator:

$ python replicator.py

Other cellular automata implementations in the top-level directory are run the same way.

Alternatively, a general-purpose neighbor-oriented automata state transition function is also available. This will take an array encoding the current state (see below) along with a rule string, and outputs the next state for all cells. rule_string.py shows how to use this.

End each program using a keyboard interrupt (ctrl-c).

How it's written

The game grid is encoded as a simple m by n array (default 100x100 in the code) of zeros and ones. In each program, a state transition is determined for each pixel by looking at the 8 pixel values all around it, and counting how many of them are "alive", then applying some rules based that number. Since the "alive" or "dead" states are just encoded as 1 or 0, this is equivalent to summing up the values of all 8 neighbors.

If you want to do this for all pixels in a single shot, this is equivalent to computing the 2D convolution between the game state array and the matrix [[1,1,1],[1,0,1],[1,1,1]]. Convolution is an operation that basically applies that matrix as a "stencil" at every position around the game grid array, and sums up the values according to the values in that stencil. And convolution can be very efficiently computed using the FFT, thanks to the Fourier Convolution Theorem.

One side effect: the convolution using FFT implicitly involves periodic boundary conditions, so the game grid is "wrapped" around itself (like in Pacman, or Mario Bros. 2). If you wanted to change this, you would just have to modify the 2D convolution function to use an orthogonal form of the DCT instead of the FFT. This would correspond to "hard" (i.e. Dirichlet) boundary conditions on the convolution operator.

I think you could do this with scipy using the 1D orthogonal dct provided:

from scipy import fftpack
fftpack.dct(data, norm='ortho')

but I haven't tried that yet. You'd have to define a dct2() method using fftpack.dct and separability (ie. the 1D transform matrix is rank-one, and the 2D transform operator is the Kronecker product of two 1D transforms ).

Goals

Ultimately, I'd like to study automata patterns with rule sets that depend on information beyond only the immediate 8 neighbors to a cell. For this code, this basically comes down to finding interesting behavior that results from using different convolution kernels.

More Repositories

1

webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Python
3,093
star
2

Python-Arduino-Command-API

A Python library for communicating with Arduino microcontroller boards
Python
406
star
3

stl_tools

Python code to produce STL geometry files from plain text, LaTeX code, and 2D numerical arrays (matrices)
Python
253
star
4

simple-cython-example

A small project template that shows how to wrap C code into python using cython, along with other packaging concepts
Python
123
star
5

examgen

A Python class that can automatically generate mathematics exams, with solution keys, using Sympy and LaTeX.
Python
53
star
6

math-genealogy

A python script to collect data from the mathematics genealogy project and generate genealogy graphs, combine graphs, etc.
Python
34
star
7

magiceye-solver

A python code to automatically "solve" magic eye autostereograms
Python
30
star
8

pyemotiv

A Python library for data acquisition from the Emotiv Epoc EEG headset, using the research SDK.
Python
22
star
9

pygmaps-extended

Python wrapper for Google Maps JavaScript API V3 and Google Earth API.
Python
16
star
10

github-auto-tools

Python command line tool to clone all public repos and gists from a single github account, and populate empty new repos with a set of templated default files.
Python
15
star
11

pandemic

Python based dynamical optimization of a pandemic disease model
Python
11
star
12

python-screenshot

Python library to make screen captures and save the images to the cwd
Python
11
star
13

pyneulog

Python interface for Neulog GSR sensor
Python
8
star
14

maximum-submatrix-sum

Python code that implements an algorithm for finding the maximum submatrix sum of an M by N matrix
Python
5
star
15

pyrovio

Python code to interface with the Wowwee Rovio robotic webcam
Python
4
star
16

garage_door_control

Android, spark firmware, and fritzing file for garage door control project
Java
4
star
17

Rimworld_roof_editor

Tool for editing roof-types on Rimworld maps
Python
4
star
18

latex-homework-template

A multi-column, landscape-oriented LaTeX template for homework assignments
3
star
19

imresize

A replacement for scipy.misc.imresize that does not depend on PIL
Python
3
star
20

opencv-data-plotter

A python code for fast, real-time 2d data plotting for codes that already have opencv as a dependency.
Python
2
star
21

Atlas

OpenMDAO implementation of the Aerovelo Atlas human-powered helicopter design problem
C
2
star
22

data-store

Some python tools for doing key-value storing
Python
2
star
23

SGNDI

Separable Grid N-Dimensional Interpolator: A multi-dimensional interpolating class with based on 1D interpolation.
Python
2
star
24

CVtemplate

Template for a real time computer vision project using OpenCV
Python
2
star
25

talk_inverse_probs

A short talk on discrete ill-posed inverse problems
Python
2
star
26

arduino-sketch-demos

A collection of various arduino demo sketches
Processing
2
star
27

SwiftFiniteDifference.playground

experimentation with first class functions in Swift
Swift
2
star
28

quick_imshow

Python code to quickly display an image with matplotlib. Meant for debugging image processing code.
Python
2
star
29

CADRE-old

OpenMDAO implementation of the CADRE CubeSat design problem
Python
1
star
30

thearn.github.io

1
star
31

printable_ramps

IPython Notebook for generating hand-drawn 3D-printable candidate solutions to the Brachistochrone problem
JavaScript
1
star
32

pathfinding

Python
1
star
33

android_tutorial

Java
1
star
34

pickle-gzip

Small python library to save and load objects with pickle from disc, with gzip compression.
Python
1
star
35

solar

OpenMDAO solar energy model
Python
1
star