定制 christianessl/landmap-generation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

christianessl/landmap-generation

最新稳定版本:1.0.0

Composer 安装命令:

composer require christianessl/landmap-generation

包简介

Generate pixelated, random world maps in PHP.

README 文档

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

Public methods Description Default value
setWidth() map width in pixels 150
setHeight() map height in pixels 150
setColorScheme() the color scheme to use DefaultColorScheme
setWaterLevel() percentage of the map to be water 70
setInterpolationMode() when set, only every fourth pixel is actually calculated in heightmap generation. (as the calculation costs a lot of performance) Neighbouring pixels will be interpolated. Highly recommended. true

Class DefaultColorScheme

Constructor arguments Description Default value
ShaderInterface $shader The shader to use for this color scheme. If none is passed, "NullShader" will be used (which does no shading at all). NullShader

Class LandmapGenerator

Constructor arguments Description Default value
GeneratorSettingsInterface $settings The settings for the LandmapGenerator: MapSettings or DefaultSettings. -
string $seed Seed for the Random number generator. -
HeightmapGeneratorInterface $heightmapGenerator The algorithm for generating the heightmap. DiamondSquareHeightmapGenerator
WaterLevelGeneratorInterface $waterLevelGenerator The algorithm for placing the water level WaterLevelGenerator

Implemented Shaders

Class name Description
NullShader Does no shading at all.
FlatShader Simple shading with flat looking colors.
DetailShader Highly detailed altitudes in the map. No steps between the colors.

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

统计信息

  • 总下载量: 3.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2019-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固