simplex-noise.js is a fast simplex noise implementation in Javascript. It works in the browser and on nodejs.
It requires typed arrays, if you want to use it in browsers without support you will need to use a polyfill like typedarray.js.
- Simple 2D plasma demo on codepen.io.
- A more complex 3D voxel world generation example.
- Real world usage for creating film grain in my analog film emulator.
// initializing a simplex instance
// do this only once it's relatively expensive
var simplex = new SimplexNoise(),
value2d = simplex.noise2D(x, y),
value3d = simplex.noise3D(x, y, z),
value4d = simplex.noise4D(x, y, z, w);
You can also pass an alternative random function to the constructor that is used to build the permutation table:
var simplex = new SimplexNoise(Math.random),
value2d = simplex.noise2D(x, y);
This can be used with a PRNG like alea to initialize the noise function with a seed:
var random = new Alea(seed),
simplex = new SimplexNoise(random),
value2d = simplex.noise2D(x, y);
The ALEA PRNG can be found on npm.
Node.js is also supported, you can install the package using npm.
var SimplexNoise = require('simplex-noise'),
simplex = new SimplexNoise(Math.random),
value2d = simplex.noise2D(x, y);
For development you can open perf/index.html
and watch the console or run node perf/benchmark.js
in a shell.
There is also a rake task for comparing your current changes can also run make compare
.
The command works using git stash.
There are some simple buster.js tests for this library to run them first install buster.js and jshint:
npm install buster
# if you haven't done so already
npm install -g jshint
make tests
- Small performance improvement for 2D noise
- Increased entropy by fixing a little initialization issue.
- AMD support
- Changed node.js api, SimplexNoise is now exported directly.
- Added unit tests
- Initial Release
Copyright (c) 2015 Jonas Wanger, licensed under the MIT License (enclosed)
This is mostly a direct javascript port of the Java implementation by Stefan Gustavson and Peter Eastman.