cellular_automata 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 29

Cellular Automata #

Build Status Pub Package Version Latest Dartdocs

A cellular automata library / playground written in Dart. Happily accepting pull requests! ^_^

Features #

  • Simple system for writing optimised rules
  • MCell rules compatible, current systems supported:
    • MCell Generations
  • Generators to seed the simulation
  • Map states to colours/characters for rendering
  • Controls: pause, resume, stepBack, stepForward
  • Stale simulation detection (repeating generations or patterns in activity)
  • Utilises the package:logging for debug & info (view on pub)
  • Decoupled renderers:
    • Canvas: (Web), fullscreen support
    • StageXL: (Web), WebGL, fullscreen support, (performance issues with big scenes)

Implemented rules/simulations #

  • Conway's Game of Life (source)
  • Conway's Game of Life Simple (binary states) (source)
  • Brian's Brain (source)
  • Majority Vote (source)
  • MCell Generations rule parser. See the demos including:
    • Star Wars
    • Rake
    • Star Wars
    • Sedi Mental
    • Frozen Sprials

Examples #

See the examples/ folder for some simple code examples.

Web demos #

See the demos/ folder for demos. You can try the hosted demos here.

Roadmap #

  • En route: Multiple simulations/rule-sets running in a single scene
  • En route: Flutter renderer
  • Add more MCell rule parsers
  • Add MCell rule database
  • Add multiple states to 'Majority Vote'
  • Add visual feedback to show processing of simulations - useful whilst building and debugging
  • Support for entities to exist which would allow for simulations such as Langton's Ant
  • Add a multiple states generator
  • Add more tests
  • Transitions for switching between two simulations
  • Generated color palettes
  • Interactive mode (edit mode)
  • Analysis tools (histograms for state counts)
  • Add an LED Matrix renderer for raspberry pi using GPIO pins
  • Hexagonal grids
  • Infinite world size support

Credits #

Please see the credits file for a list of the authors that discovered the rules that have been implemented in this project.

Licence #

Please see the cellular_automata license.

Changelog #

1.0 #

  • Web renderers have been moved into a new package: cellular_automata_web. This core package can now be loaded into none web enviroments such as flutter etc.
  • example/ folder now contains numerous ascii based examples that can be run from command-line
  • Player renamed Scene
  • Simulator renamed Automaton
  • onRender renamed onPaint
  • SimulationCompleteReason renamed SceneCompleteReason
  • onPaintFull now available which will paint a full scene every generation. Note: This is a not as performant as onPaint which will only paints the changes in a scene
  • AsciiRenderer added. This is a very simple text based renderer, used in the examples.
  • onPrepare fired before scene starts running. This is when a generator could be used to seed the automaton.
  • Now supports multiple automata running in a single scene. used addAutomaton() to add automata.
  • Recased all enums to camel case.

0.9 #

0.8 #

  • MCellGenerations rule parser added. This can parse all MCell Generations configs.
  • Credits
  • onStable renamed onComplete, now passes SimulatorCompleteReason enum value. Current states are: duration and stable
  • Demos updated to include MCell
  • Credits file created to credit those that wrote/discovered the rules
  • Decent Refactor, reorganised stuff!
    • Simulator renamed Player
    • Array2D replaced with CellGrid which combines Array2D with CA specific functionality which simplifies CellWorld.
    • CARules interface updated
    • CellWorld renamed Simulator

0.7 #

  • Optimised MajorityVote Rules, utilises edge detection to determine activity
  • Added paintFullSize option to CanvasRenderer: This allows the scene to be painted at actual size rather than small and then resized via CSS.
  • Added maxAge as a Simulator constructor parameter, if this is set then onStable is called when the generation count surpasses maxAge
  • Added package:logging so debug information can be enabled / disabled
  • Updated demos

0.6 #

  • Stable simulation detection. This broadcast to the onStable stream after detecting repeating identical generations or repeating generation activeCellCount patterns spanning up to 8 generations.
  • Demos updated to auto reset on stable scene (excluding rendering examples)

0.5 #

  • Added new default renderer for web: CanvasRenderer. This is a simple native Canvas renderer. This has been added as StageXLRenderer has performance issues with large scenes.
  • Added demos for both StageXLRenderer and CanvasRenderer
  • Demos moved over to use CanvasRenderer

0.4 #

  • Added MajorityVote Rules
  • Optimised BriansBrain processing
  • Updated demos

0.3 #

  • Added GameOfLifeSimple Rules. This simulation is a simpler version of GameOfLife, it only has binary states and implemented with minimal code
  • Added BriansBrain Rules
  • Updated demos

0.2 #

  • Optimised cell processing, now only processes cells that neighbor active states
  • Added tests (more to add)
  • Improved StageXL bitmap colours crispness by adding frame margin

0.1 #

  • Refactored so Rule's cell-states are now passed as generic types in to the Cell World for better analyzer & tooling support
  • Added a CAGenerators for generating/seeding worlds
  • Renderers are now further decoupled from the Simulation. They now just require an CellGrid containing states expressed in a palette.
  • Added a very simple demo (simple_example.dart) to show minimum setup code
  • CellWorld now stores full cell-states and Rules also deal with full cell-states which makes code more readable
  • Fixed mathematical generators

0.0 #

  • Initial version, includes basic implementation of GameOfLife with StageXLRenderer
  • Hosted demos


import 'package:cellular_automata/cellular_automata.dart';
import 'package:cellular_automata/rules.dart';
import 'package:cellular_automata/renderer_ascii.dart';

// Simple example showing the 'Brian Brain' automaton.
// For prettier outputs see the platform specific renderers
// Run in terminal with command: pub run example/example.dart
void main() {
  final width = 48;
  final height = 22;

  final palette = new Map<BriansBrainStates, String>.from({
    BriansBrainStates.dead: '_',
    BriansBrainStates.dying: 'x',
    BriansBrainStates.living: 'O'

  final AsciiRenderer renderer = new AsciiRenderer();
  final scene = new Scene<String>(
    width: width,
    height: height,
    fpsTarget: 10,
    ..onPrepare.listen((int count) {
            automaton: new Automaton<BriansBrainStates, String>(
          width: width,
          height: height,
          defaultState: BriansBrainStates.dead,
          palette: palette,
          wrap: true,
          rules: new BriansBrain(),
        )..applyGenerator(new MathematicalGenerator<BriansBrainStates>(
                type: MathematicalGenerators.random,
                valueTrue: BriansBrainStates.living,
                valueFalse: BriansBrainStates.dead)));
    ..onFullPaint.listen((CellGrid<String> snapshot) {
    ..onComplete.listen((SceneCompleteReason s) {
      print('All done! (Generation ${scene.generationCounter})');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  cellular_automata: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:cellular_automata/cellular_automata.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/cell_grid.dart. (-10.44 points)

Analysis of lib/src/cell_grid.dart reported 22 hints, including:

line 20 col 15: Unnecessary new keyword.

line 23 col 14: Unnecessary new keyword.

line 25 col 12: Unnecessary new keyword.

line 29 col 18: Unnecessary new keyword.

line 30 col 39: Unnecessary new keyword.

Fix lib/src/scene.dart. (-9.08 points)

Analysis of lib/src/scene.dart reported 19 hints, including:

line 12 col 14: Unnecessary new keyword.

line 35 col 7: Unnecessary new keyword.

line 39 col 7: Unnecessary new keyword.

line 44 col 7: Unnecessary new keyword.

line 49 col 44: Unnecessary new keyword.

Fix lib/src/automaton.dart. (-6.78 points)

Analysis of lib/src/automaton.dart reported 14 hints, including:

line 9 col 14: Unnecessary new keyword.

line 33 col 11: Use = to separate a named parameter from its default value.

line 41 col 7: DO use curly braces for all flow control structures.

line 45 col 11: DO use curly braces for all flow control structures.

line 73 col 21: Use = to separate a named parameter from its default value.

Fix additional 7 files with analysis or formatting issues. (-13.36 points)

Additional issues in the following files:

  • lib/src/rules/majority_vote.dart (8 hints)
  • lib/src/generators/mathematical.dart (6 hints)
  • lib/src/rules/game_of_life_simple.dart (5 hints)
  • lib/src/rules/mcell_generations.dart (3 hints)
  • lib/src/rules/_ca_rules.dart (2 hints)
  • lib/src/util/timer.dart (2 hints)
  • lib/src/renderers/_ca_renderer.dart (1 hint)

Maintenance suggestions

Package is getting outdated. (-68.77 points)

The package was last published 88 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.61.0 <3.0.0
logging ^0.11.3+2 0.11.4
Dev dependencies
test ^1.3.0