Procedural map generator using Perlin and simplex noise
A procedural 2D map generator based on Perlin / simplex noise
Create a Canvas
in your HTML code:
<canvas id="map-canvas" width="800" height="400"></canvas>
Create a HeightMap
with the MapGenerator
in your JS code:
var NoiseMap = require('noise-map');
var generator = new NoiseMap.MapGenerator();
var heightmap = generator.createMap(400, 200, {type: 'perlin'});
var context = document.getElementById('map-canvas').getContext('2d');
heightmap.draw(context, 800, 400, NoiseMap.STYLE.GRAY);
This module allows you to create random heightmaps with Perlin and simplex noise,
edit their data with utility methods, and display them on a Canvas.
The module exposes four items:
MapGenerator
: A configurable map constructorHeightMap
: A data container for noise valuesSTYLE
: An enum for the map rendering styleColorizer
: An internal map rendering toolnew MapGenerator(seed = random(), configuration = {})
Instantiate a new MapGenerator, that can be used repeatedly to create different maps. You usually need only one MapGenerator
.
Arguments:
seed
: optionnal, an integer used a a seed for the noise functions
configuration
: optionnal, an object describing the current configuration of this generator:
"simplex"
or "perlin"
)1
)0.5
)0.5
)0.5
)false
)setSeed(seed)
setConfig(config)
newMap(width, height, config = {})
Return a new HeightMap
with the input dimensions, and fill it wil random values in [0, 1];
new HeightMap(width, height, data = [])
Create a new HeightMap
with dimensions (width
, height
).
The argument data
is an optionnal 1D Array
containing the values of the heightmap.
get(x, y)
Get the value at (x
, y
)
set(x, y, value)
Set the value at (x
, y
) to value
scaleValues(coef)
Exponentially scale the values of the heightmap, by a coefficient coef
;
stepValues(n)
Floor the values of the heightmap, resulting in n
steps;
inverseValues()
Inverse the values of the heightmap
draw(context, outputWidth, outputHeight, style = STYLE.GRAY, enableShadow = false)
Canvas
elementThe style can be one of: STYLE.GRAY
, STYLE.REALISTIC
, STYLE.GEOLOGIC
, STYLE.HEATMAP
You can install the module with npm:
npm install noise-map
You can import the module with unpkg:
<script type="text/javascript" src="https://unpkg.com/noise-map@latest"></script>
You can clone the repository & include the noise-map.js
file in your project:
git clone https://github.com/ogus/noise-map.git
This project is licensed under the WTFPL - see LICENSE for more details