Create two-dimensional Cyclic Cellular Automaton with PHP. Export results as (animated) images. Includes presets of working rules.
This project can be used to run two-dimensional Cyclic Cellular Automaton (CCA). Results can be saved as static images of animated gifs. The configuration (of the CCA or images) can be set using various presets or customized to your own liking.
$ composer require barryvanveen/php-cca
Please note that you need PHP 7.0 or higher and the GD extension to install this package.
// using the ConfigBuilder $builder = Builders\ConfigBuilder::createFromPreset(Config\Presets::PRESET_CCA); $builder->rows(50); $builder->columns(50); $config = $builder->get(); // or build it from scratch $config = new Config([ Config\Options::NEIGHBORHOOD_SIZE => 1, Config\Options::NEIGHBORHOOD_TYPE => Config\NeighborhoodOptions::NEIGHBORHOOD_TYPE_NEUMANN, Config\Options::STATES => 14, Config\Options::THRESHOLD => 1, Config\Options::ROWS => 50, Config\Options::COLUMNS => 50, ]);
\Barryvanveen\CCA\Config\Presets.php you can find all available presets.
// get a single state $runner = new Runner($config, Factories\CCAFactory::create($config)); $state = $runner->getLastState(234); // get a set of states $runner = new Runner($config, Factories\CCAFactory::create($config)); $states = $runner->getFirstStates(123); // get a set of states that loops (if possible) $runner = new Runner($config, Factories\CCAFactory::create($config)); $states = $runner->getFirstLoop(500);
The Runner is probably sufficient for most scenarios but if you want more control you can control the CCA yourself. Just look at the Runner implementation to get an idea of how this works.
// create a static Gif from a single stae $image = Generators\Gif::createFromState($config, $state); $image->save('/path/to/output.gif'); // create a static Png from a single state $image = Generators\Png::createFromState($config, $state); $image->save('/path/to/output.png'); // create an animated Gif $image = Generators\AnimatedGif::createFromStates($config, $states); $image->save('/path/to/output.gif');
/examples folder contains some scripts to generate different kinds of images. Here are some example images:
Please see the releases for more information on what has changed recently.
$ composer test
If you discover any security related issues, please email firstname.lastname@example.org instead of using the issue tracker.
All preset configurations are taken from http://psoup.math.wisc.edu/mcell/rullex_cycl.html which is the work of Mirek Wójtowicz.
The colors for the images are generated using talesoft/phim which is a project by Torben Köhn.
Animated gifs are created using lunakid/anim-gif.
The MIT License (MIT). Please see License File for more information.