<?php ini_set('display_errors', 'On'); require_once __DIR__ . '/../src/DiamondAndSquare.php'; $gen = new MapGenerator\DiamondAndSquare(); $size = 8; $gen->setPersistence(1.8); $gen->setSize($size); $gen->setMapSeed(uniqid()); $map = $gen->generate(); $image = imagecreatetruecolor($gen->getSize(), $gen->getSize()); $max = 0; $min = PHP_INT_MAX; for ($iy = 0; $iy < $gen->getSize(); $iy++) { for ($ix = 0; $ix < $gen->getSize(); $ix++) { $h = $map[$iy][$ix]; if ($min > $h) { $min = $h; } if ($max < $h) { $max = $h; } } } $diff = $max - $min; for ($iy = 0; $iy < $gen->getSize(); $iy++) { for ($ix = 0; $ix < $gen->getSize(); $ix++) { $h = 255 * ($map[$iy][$ix] - $min) / $diff; $color = imagecolorallocate($image, $h, $h, $h); imagesetpixel($image, $ix, $iy, $color); }
<?php $start = microtime(true); ini_set('display_errors', 'On'); require __DIR__ . '/../src/DiamondAndSquare.php'; $size = 3; $gen = new MapGenerator\DiamondAndSquare(); $gen->setSize($size); $gen->setPersistence(50); $gen->setMapSeed('uniqueSeed'); $memStart = memory_get_usage(); if ($size > 3) { $gen->generate(); } else { print_r($gen->generate()); } echo sprintf('Memory Limit: %s', ini_get('memory_limit')) . PHP_EOL; echo sprintf('Memory Usage: %s', round((memory_get_usage() - $memStart) / 1024 / 1024, 2)) . 'M' . PHP_EOL; echo sprintf('Memory Peak Usage: %s', round(memory_get_peak_usage() / 1024 / 1024, 2)) . 'M' . PHP_EOL; echo sprintf('Time: %s', round(microtime(true) - $start, 3)) . PHP_EOL;