https://github.com/esimov/simplexnoise.js
Javascript simplex noise implementation based on Stefan Gustavson paper: http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
https://github.com/esimov/simplexnoise.js
Last synced: 2 months ago
JSON representation
Javascript simplex noise implementation based on Stefan Gustavson paper: http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
- Host: GitHub
- URL: https://github.com/esimov/simplexnoise.js
- Owner: esimov
- License: mit
- Created: 2016-04-01T07:35:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-01T14:17:07.000Z (about 9 years ago)
- Last Synced: 2025-01-30T05:13:33.362Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simplexnoise.js
This is a javascript port of the original java version implemented by Stefan Gustavson (http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java).
It uses typed arrays for an extra speed boost. It's quite fast (see the example provided).
### Usage example
To check the example provided you have two option. Either by using `npm install`. This will install `node-static` package to serve static files in the node way. Then you can run:
```
node app.js
```
After this you can access the server from the browser by typing `localhost:3000`.Another way is to run `index.html` directly.
### Basic usage
```javascript
var simplex = new NOISE.Simplex();
simplex.init();
simplex.noiseDetail(1, 0.5);
```This will initialize the noise with some initial values the first one representing the `octaves`, the second one the `persistence`.
After intialization you have to call the basic `noise` function passing as parameters the `x`, `y`, `z`,`w` values, depending on the target corrdinate system used (2d, 3d, 4d).
For example:
```javascript
for (var x = 0; x < canvas.width; x++) {
for (var y = 0; y < canvas.height; y++) {
var value = Math.abs(simplex.noise(x / 100, y / 100, height));
value *= 256;var cell = (x + y * canvas.width) * 4;
data[cell] = data[cell + 1] = data[cell + 2] = value;
data[cell] += Math.max(0, (25 - value) * 8);
data[cell + 3] = 255; // alpha.
}
}
```For a more complex use case please check my simplex noise powered minecraft experiment: www.esimov.com/experiments/javascript/minecraft_v2/