PHP code example of cmcdota / php-graph-to-svg

1. Go to this page and download the library: Download cmcdota/php-graph-to-svg 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/ */

    

cmcdota / php-graph-to-svg example snippets


use Cmcdota\PhpGraphToSvg\Board;

//Describe Vertexes and their edges (links)
$vertexes = [
    0 => ['name' => '0', 'fill'=> '80ff80', 'edges' => [1]],
    1 => ['name' => '1','fill'=> 'c0c0c0', 'edges' => [2]],
    2 => ['name' => '2', 'edges' => [3]],
    3 => ['name' => '3', 'edges' => [1]],
    5 => ['name' => '5', 'edges' => [0]],
    6 => ['name' => '6', 'edges' => [5]],
    7 => ['name' => '7', 'edges' => [6,3]],
    8 => ['name' => '8', 'edges' => [6,7]],
    9 => ['name' => '9', 'edges' => [5]],
    10 => ['name' => '10', 'edges' => [9]],
    11 => ['name' => '11', 'edges' => [10,8]],
    12 => ['name' => '12', 'edges' => [9,11]],
];
$board = new Board($vertexes, $params);
echo "<html lang='EN'>";
for ($i = 1; $i <= 10; $i++) {
    $svg = $board->renderSVG();
    file_put_contents("step$i.svg", $svg);
    echo "<div style='width:50%'><img src='step$i.svg'  alt='next step' border='1'></div>";
    $board->calculateAndMove(10);
}

$params=[
    'randomSpawn' => false
];