PHP code example of barryvanveen / php-cca

1. Go to this page and download the library: Download barryvanveen/php-cca library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

barryvanveen / php-cca example snippets


// 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);  

// 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');
 bash
$ composer 
 php
// 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,
]);