barryvanveen / php-cca
使用PHP创建二维循环细胞自动机。结果可以导出为(动画)图像。包含工作规则的预设。
2.0.1
2018-07-17 20:05 UTC
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-09-06 13:15:21 UTC
README
该项目可以用于运行二维 循环细胞自动机 (CCA)。结果可以保存为静态图像或动画GIF。可以使用各种预设或自定义配置(CCA或图像)。
安装
通过Composer
$ composer require barryvanveen/php-cca
请注意,您需要PHP 7.0或更高版本以及GD扩展来安装此包。
用法
创建配置
// 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
中可以找到所有可用的预设。
运行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);
运行器对于大多数场景可能是足够的,但如果您想有更多的控制,您可以自己控制CCA。只需查看运行器的实现,以了解其工作原理。
生成图像
// 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
文件夹中包含一些生成不同类型图像的脚本。以下是一些示例图像
变更日志
有关最近更改的更多信息,请参阅 发行版。
测试
$ composer test
贡献
有关详细信息,请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT。
安全
如果您发现任何安全相关的问题,请通过电子邮件 barryvanveen@gmail.com 联系,而不是使用问题跟踪器。
致谢
所有预设配置均来自 http://psoup.math.wisc.edu/mcell/rullex_cycl.html,这是Mirek Wójtowicz的作品。
图像颜色由Torben Köhn的项目 talesoft/phim 生成。
动画GIF由 lunakid/anim-gif 创建。
鸣谢
许可协议
MIT许可协议(MIT)。有关更多信息,请参阅 许可文件。