@@ -22,59 +22,56 @@ Created something awesome with simplex-noise? Let me know so I can add it to the
22
22
23
23
``` npm i -S simplex-noise ```
24
24
25
- ## Usage
25
+ ## Usage Examples
26
+
27
+ ### ES Module Import
26
28
27
29
``` javascript
28
- // when using es modules
29
- import SimplexNoise from ' simplex-noise' ;
30
- // when using commonjs
31
- const {SimplexNoise } = require (' simplex-noise' );
30
+ // when using ES modules
31
+ import { noiseFunction2D } from ' simplex-noise' ;
32
32
```
33
33
34
- By default simplex-noise.js will use Math.random() to seed the noise.
34
+ ### CommonJS Require
35
+
35
36
``` javascript
36
- // initializing a new simplex instance
37
- // do this only once as it is relatively expensive
38
- const simplex = new SimplexNoise (),
39
- value2d = simplex .noise2D (x, y),
40
- value3d = simplex .noise3D (x, y, z),
41
- value4d = simplex .noise4D (x, y, z, w);
37
+ const { noiseFunction2D } = require (' simplex-noise' );
42
38
```
43
39
44
- You can also pass in a seed string which will then be used to initialize
45
- the noise using the built in alea PRNG.
46
- ``` javascript
47
- const simplex = new SimplexNoise (' seed' ),
48
- value2d = simplex .noise2D (x, y),
49
- sameSeed = new SimplexNoise (' seed' ),
50
- differentSeed = new SimplexNoise (' different seed' );
40
+ ### 2D
51
41
52
- sameSeed .noise2D (x, y) === value2d
53
- differentSeed .noise2D (x, y) !== value2d
42
+ ```
43
+ const noise2D = noiseFunction2D();
44
+ console.log(noise2D(x, y));
54
45
```
55
46
56
- You can also pass an alternative random function to the constructor that is
57
- used to build the permutation table.
58
- This can be used with a custom pseudo random number generator:
47
+ ### 3D
59
48
60
- ``` javascript
61
- const random = new Alea (seed),
62
- simplex = new SimplexNoise (random),
63
- value2d = simplex .noise2D (x, y);
49
+ ```
50
+ const noise3D = noiseFunction3D();
51
+ console.log(noise3D(x, y, z));
64
52
```
65
53
66
- The ALEA PRNG can be found in the npm package [ alea ] ( https://npmjs.org/package/alea ) .
54
+ ### 4D
67
55
68
- ## node.js
56
+ ```
57
+ const noise4D = noiseFunction4D();
58
+ console.log(noise4D(x, y, z, w));
59
+ ```
69
60
70
- Node.js is also supported, you can install the package using [ npm ] ( https://npmjs.org/package/simplex-noise ) .
61
+ ### Using a seed value
71
62
72
- ``` javascript
73
- const SimplexNoise = require (' simplex-noise' ),
74
- simplex = new SimplexNoise (Math .random ),
75
- value2d = simplex .noise2D (x, y);
63
+ By default simplex-noise.js will use Math.random() to seed the noise.
64
+ You can pass in a PRNG function to use your own seed value.
65
+
66
+ ```
67
+ import Alea from 'alea';
68
+ const alea = new Alea('seed');
69
+ const noise2D = noiseFunction2D(alea);
70
+ console.log(noise2D(x, y));
76
71
```
77
72
73
+ The ALEA PRNG used in the example above can be found in the [ alea] ( https://npmjs.org/package/alea ) npm package.
74
+
78
75
## Benchmarks
79
76
80
77
simplex-noise.js is reasonably quick.
0 commit comments