barryvanveen / php-cca
Create two-dimensional Cyclic Cellular Automaton with PHP. Export results as (animated) images. Includes presets of working rules.
Requires
- php: ~7.0
- ext-gd: *
- lunakid/anim-gif: ^1.3
- talesoft/phim: ^1.0
Requires (Dev)
- phpunit/phpunit: ~6.0
- slevomat/coding-standard: ^3.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-11-06 13:42:57 UTC
README
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.
Install
Via Composer
$ composer require barryvanveen/php-cca
Please note that you need PHP 7.0 or higher and the GD extension to install this package.
Usage
Creating a configuration
// 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, ]);
In \Barryvanveen\CCA\Config\Presets.php
you can find all available presets.
Running the CCA
// 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.
Generating images
// 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
The /examples
folder contains some scripts to generate different kinds of images. Here are some example images:
Changelog
Please see the releases for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email barryvanveen@gmail.com instead of using the issue tracker.
Acknowledgments
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.
Credits
License
The MIT License (MIT). Please see License File for more information.