GithubHelp home page GithubHelp logo

bastienlaby / cellular Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 205 KB

Python API to create and display cellular automaton

License: GNU General Public License v3.0

Python 100.00%
automaton conways-game-of-life langton-ant emergence cellular

cellular's Introduction

cellular

cellular is a Python API to create and display cellular automatons. It provide a class Automate that you can derivate to create custom automatons. The Automate class :

  • Provides a grid variable to store the automate's data.
  • Provides an evolves() method to override in order to describe how the system evolves at step N+1.

Example

import copy

from cellular.automate import Automate


class Blinker(Automate):
    """
    Automate that blink.
    """
    cell_data_type = bool

    def evolves(self):
        """
        Implement a blinker automate which inverse th state of every cell at each evolution.
        """
        current_gen = copy.deepcopy(self.grid)
        for i in range(self.width):
            for j in range(self.height):
                self.grid[i][j] = not current_gen[i][j]
        self.step += 1


blinker = Blinker(2, 2)
blinker.initialize()

blinker.grid[0][0] = False
blinker.grid[0][1] = True
blinker.grid[1][0] = True
blinker.grid[1][1] = False

for i in range(3):
    blinker.save_img(filepath="img/blinker/blinker.%.03d.png" % (blinker.step))
    blinker.evolves()

Installation

  • Clone this repository : git clone <repo_url>
  • Create a virtualenv (I use Python 3.7 for this project) : py -3.7 -m pip cellular
  • Move into the folder : cd cellular
  • Activate the virtualenv : .\Scripts\activate.bat (windows) or source bin/activate (linux)
  • Install the requirements : pip install -r requirements.txt

Done !

Output and convert to gif

from cellular.samples.langton import LangtonAnt

automate = LangtonAnt(50, 50)
automate.initialize()

for _ in range(0, 200):
    automate.save_img(filepath="img/langton/langton.%.03d.png" % (automate.step))
    automate.evolves()

Then some ffmpeg : ffmpeg -i img.%03d.png -vf scale=300:300 -sws_flags neighbor output.gif

Langton simulation :

Conway Game Of Life simulation :

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.