11# simplex-noise.js
2- [ ![ Tests] ( https://github.com/jwagner/simplex-noise.js/actions/workflows/tests.yml/badge.svg )] ( https://github.com/jwagner/simplex-noise.js/actions/workflows/tests.yml )
32
4- simplex-noise.js is a fast simplex noise implementation in Javascript. It works in the browser and on nodejs.
3+ [ API Documentation] ( https://29a.ch/simplex-noise/docs/classes/SimplexNoise.html )
4+
5+ [ ![ Tests] ( https://github.com/jwagner/simplex-noise.js/actions/workflows/tests.yml/badge.svg )] ( https://github.com/jwagner/simplex-noise.js/actions/workflows/tests.yml ) [ ![ TypeScript] ( https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg )] ( http://www.typescriptlang.org/ )
6+
7+
8+ simplex-noise.js is a simplex noise implementation in Javascript/TypeScript.
9+ It works in the browser and nodejs. Using Commonjs and ES Modules.
10+ It is self contained (dependency free), relatively small (about 2k minified and gzipped)
11+ and fairly fast (about 20 nanoseconds for a sample of 2d noise).
512
613## Demos
714
815- Simple 2D plasma on [ codepen.io] ( http://codepen.io/jwagner/pen/BNmpdm/?editors=001 ) .
916- [ 3D voxel world generation] ( http://29a.ch/sandbox/2012/voxelworld/ ) example.
1017- Film grain in [ analog film emulator] ( http://29a.ch/film-emulator/ ) .
1118
19+ Created something awesome with simplex-noise? Let me know so I can add it to the list.
20+
1221## Installation
1322
1423``` npm i -S simplex-noise ```
1524
1625## Usage
1726
27+ ``` javascript
28+ // when using es modules
29+ import SimplexNoise from ' simplex-noise' ;
30+ // when using commonjs
31+ const {SimplexNoise } = require (' simplex-noise' );
32+ ```
33+
1834By default simplex-noise.js will use Math.random() to seed the noise.
1935``` javascript
2036// initializing a new simplex instance
@@ -61,12 +77,18 @@ const SimplexNoise = require('simplex-noise'),
6177
6278## Benchmarks
6379
64- - [ Comparison between 2D and 3D noise] ( http://jsperf.com/simplex-noise/4 )
65- - [ Comparison with simplex implementation in three.js] ( http://jsperf.com/simplex-noise-comparison/3 )
80+ simplex-noise.js is reasonably quick.
81+ According to ` perf/benchmark.js ` I can perform about 50 million ` noise2D() ` calls/second on a single thread on my desktop (Ryzen 5950X).
82+ So ~ 20 nanoseconds per call.
6683
67- For development you can open ` perf/index.html ` and watch the console or run ` node perf/benchmark.js ` in a shell.
68- There is also a rake task for comparing your current changes can also run ` make compare ` .
69- The command works using git stash.
84+ ```
85+ $ node perf/index.js
86+ 27745787.933336906
87+ init: 192,590 ops/sec ±1%
88+ noise2D: 57,928,891 ops/sec ±1%
89+ noise3D: 34,159,230 ops/sec ±0%
90+ noise4D: 24,589,786 ops/sec ±0%
91+ ```
7092
7193## Tests
7294
@@ -78,8 +100,13 @@ npm install && npm test
78100## Changelog
79101
80102### main
103+ - Changed module structure. When using bundlers that import the es module even using require() the import might need to be updated.
81104- Dependency update
82105- Setting sideEffects: false in package.json
106+ - Added snapshot tests
107+ - Code converted to typescript, the package can of course still be used from regular JS
108+ - Dropped bower
109+ - Added support for es modules
83110
84111### 2.4.0
85112- Included a PRNG based on ALEA to directly allow seeding
@@ -119,12 +146,12 @@ you will need to use a polyfill like [typedarray.js](http://www.calormen.com/pol
119146
120147
121148## License
122- Copyright (c) 2015 Jonas Wagner, licensed under the MIT License (enclosed)
149+ Copyright (c) 2021 Jonas Wagner, licensed under the MIT License (enclosed)
123150
124151## Credits
125152This is mostly a direct javascript port of the [ Java implementation] ( http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java )
126153by Stefan Gustavson and Peter Eastman.
127154
128155The integrated pseudo random generator is based on code by by Johannes Baagøe.
129156
130- The typescript definition has been provided by [ Neonit] ( https://github.com/Neonit ) .
157+ The initial typescript definition has been provided by [ Neonit] ( https://github.com/Neonit ) .
0 commit comments