Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify interface #21

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
"rules": {
"indent": [
"error",
2
2,
{ "SwitchCase": 1 }
],
"linebreak-style": [
"error",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
shrinkwrap.yaml
39 changes: 14 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,21 @@ simplex-noise.js is a fast simplex noise implementation in Javascript. It works

## Usage

By default simplex-noise.js will use Math.random() to seed the noise.
```javascript
// initializing a new simplex instance
// do this only once as it is relatively expensive
var simplex = new SimplexNoise(),
value2d = simplex.noise2D(x, y),
value3d = simplex.noise3D(x, y, z),
value4d = simplex.noise4D(x, y, z, w);
var noise = simplex(Math.random),
value2d = noise(x, y),
value3d = noise(x, y, z),
value4d = noise(x, y, z, w);
```

You can also pass in a seed string which will then be used to initialize
the noise using the built in alea PRNG.
```javascript
var simplex = new SimplexNoise('seed'),
value2d = simplex.noise2D(x, y),
sameSeed = new SimplexNoise('seed'),
differentSeed = new SimplexNoise('different seed');

sameSeed.noise2D(x, y) === value2d
differentSeed.noise2D(x, y) !== value2d
```

You can also pass an alternative random function to the constructor that is
used to build the permutation table.
This can be used with a custom pseudo random number generator:
You can also pass an alternative random function to the function that is used to build the permutation table. This can be used with a custom pseudo random number generator:

```javascript
var random = new Alea(seed),
simplex = new SimplexNoise(random),
value2d = simplex.noise2D(x, y);
noise = simplex(random),
value = noise(x, y);
```

The ALEA PRNG can be found on in the npm package [alea](https://npmjs.org/package/alea).
Expand All @@ -50,9 +35,9 @@ The ALEA PRNG can be found on in the npm package [alea](https://npmjs.org/packag
Node.js is also supported, you can install the package using [npm](https://npmjs.org/package/simplex-noise).

```javascript
var SimplexNoise = require('simplex-noise'),
simplex = new SimplexNoise(Math.random),
value2d = simplex.noise2D(x, y);
var simplex = require('simplex-noise'),
noise = simplex(Math.random),
value = noise(x, y);
```

## Benchmarks
Expand All @@ -73,6 +58,10 @@ npm install && npm test

## Changelog

### 3.0.0
- Changed function signature to `simplex(random)(x[, y, z, w]) -> noise`
- Added support for 1D noise

### 2.4.0
- Included a PRNG based on ALEA to directly allow seeding
- Included typescript definitions
Expand Down
19 changes: 0 additions & 19 deletions alea.md

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplex-noise",
"version": "2.4.0",
"version": "3.0.0",
"description": "simplex-noise is a fast simplex noise implementation in Javascript. Works in node and in the browser.",
"homepage": "https://github.com/jwagner/simplex-noise.js",
"author": "Jonas Wagner <[email protected]> (http://29a.ch/)",
Expand Down
20 changes: 11 additions & 9 deletions perf/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
var Benchmark = this.Benchmark || require('benchmark');
var SimplexNoise = this.SimplexNoise || require('../simplex-noise');
var simplex = new SimplexNoise();
var simplex = this.simplex || require('../simplex-noise');

var suite = new Benchmark.Suite('simplex-noise')
.add('init', function() {
var simplex = new SimplexNoise();
var noise = simplex(Math.random);
})
.add('noise1D', function() {
for (var x = 0; x < 8; x++) {
noise(x / 8);
}
})
.add('noise2D', function() {
for (var x = 0; x < 8; x++) {
for (var y = 0; y < 8; y++) {
for (var z = 0; z < 8; z++) {
simplex.noise2D(x / 8, y / 8);
}
noise(x / 8, y / 8);
}
}
})
.add('noise3D', function() {
for (var x = 0; x < 8; x++) {
for (var y = 0; y < 8; y++) {
for (var z = 0; z < 8; z++) {
simplex.noise3D(x / 8, y / 8, z / 8);
noise(x / 8, y / 8, z / 8);
}
}
}
Expand All @@ -28,7 +30,7 @@ var suite = new Benchmark.Suite('simplex-noise')
for (var x = 0; x < 8; x++) {
for (var y = 0; y < 8; y++) {
for (var z = 0; z < 8; z++) {
simplex.noise3D(x / 8, y / 8, z / 8);
noise(x / 8, y / 8, z / 8);
}
}
}
Expand All @@ -37,7 +39,7 @@ var suite = new Benchmark.Suite('simplex-noise')
for (var x = 0; x < 8; x++) {
for (var y = 0; y < 8; y++) {
for (var z = 0; z < 8; z++) {
simplex.noise4D(x / 8, y / 8, z / 8, (x + y) / 16);
noise(x / 8, y / 8, z / 8, (x + y) / 16);
}
}
}
Expand Down
Loading