christianessl/landmap-generation

Generate pixelated, random world maps in PHP.

1.0.0 2019-02-26 19:28 UTC

This package is auto-updated.

Last update: 2024-11-06 13:58:10 UTC


README

Generate pixelated, random world maps in PHP.

Code Climate Latest Stable Version Total Downloads Latest Unstable Version License

This is a simple landmap generator implemented in PHP. It supports generating a heightmap, setting up a water level, colorizing and shading. The outputted result will be in pixel style.

Screenshot

1. Installation

composer require christianessl/landmap-generation.

2. Usage

require __DIR__ . '/vendor/autoload.php';

use ChristianEssl\LandmapGeneration\Settings as Settings;
use ChristianEssl\LandmapGeneration\Generator as Generator;
use ChristianEssl\LandmapGeneration\Color as Color;
use ChristianEssl\LandmapGeneration\Color\Shader as Shader;
use ChristianEssl\LandmapGeneration\Enum as Enum;
use ChristianEssl\LandmapGeneration\Utility as Utility;

$seed = 'otters_are_awesome!';
$settings = (new Settings\MapSettings())
    ->setColorScheme(new Color\DefaultColorScheme(new Shader\FlatShader()))
    ->setWidth(500)
    ->setHeight(300)
    ->setWaterLevel(60);

$landmapGenerator = new Generator\LandmapGenerator($settings, $seed);
$map = $landmapGenerator->generateMap();

$image = Utility\ImageUtility::createImage($map);
Utility\ImageUtility::outputImage($image, Enum\FileType::PNG);

3. Example output

500x300 pixels

seed: 'otters_are_awesome!'

60% water, flat shader

Screenshot

30% water, flat shader

Screenshot

60% water, detailed shader

Screenshot

60% water, no shader

Screenshot

4. Configuration options

Class MapSettings

Class DefaultColorScheme

Class LandmapGenerator

Implemented Shaders

TODO

  • implement a perlin noise algorithm as example (much faster than diamond square)
  • refactor and decouple ImageUtility
  • possibility to cache the heightmap generation (maybe as a json tree?)
  • port the diamond square algorithm to GO (in another project) and add the option to connect the php project to the GO library