vesuvius
v1.0.3
Published
Simplex noise points map (2D and 3D) generator
Downloads
4
Maintainers
Readme
Vesuvius
When working on a new project, I needed a way to procedurally generate points. I used simplex-noise for this and wrote a sort of wrapper for the functionality I needed.
It's open source, so it may be of some help to some of you. The module uses procedural noise (specifically simplex noise) to generate a map (array) of points. These points are noise values exceeding a set threshold. For my use case, these points were stars in a procedurally generated 'universe', but for you they can be anything you want.
So, how does it work?
Install
npm install vesuvius --save
Use it (duh!)
var Generator = require('vesuvius').Generator;
// Create a new Generator object with an integer seed value (4443 in this case)
var generator = new Generator(4443);
You can also pass an options array as the second parameter. These can define boxSize
, threshold
and dimensions
(in the same way as below).
// Set the box size to 10
// For 2D, this means a 10x10 (100) grid
// For 3D this means a 10x10x10 (1000) grid,
// For 4D, this means a 10x10x10x10 (10,000) grid
generator.boxSize(10);
// Set the threshold value
// All values lower than this will not be added to the map
generator.threshold(0.75);
// Set the dimensions for the generator
// 2: 2D (x,y)
// 3: 3D (x, y, z)
// 4: 4D (x, y, z, w)
generator.dimensions(3);
And then, generate the map:
// Generate the map
var map = generator.generate();
The result will be something like this (truncated):
[
{"x":0,"y":2,"z":3},
{"x":0,"y":2,"z":6},
{"x":0,"y":5,"z":8},
{"x":0,"y":6,"z":1},
{"x":0,"y":7,"z":0},
{"x":0,"y":9,"z":4},
{"x":1,"y":0,"z":3},
{"x":1,"y":0,"z":4},
{"x":1,"y":1,"z":2},
{"x":1,"y":1,"z":8}
]
Note that the Generator does not cache the map in any way! Calling generator.generate()
a second time will recalculate all over again and return the same data regardless (since it's procedural noise), if none of the parameters have changed.
Changelog
- 1.0.3 - 19 November 2015
- Replaced
Alea
(repo) withMersenneTwister
(repo) as the pseudo-random number generator of choice
License
Copyright 2015 Michiel van der Velde.
This software is licensed under the MIT License.