Skip to content

Commit d9fa53d

Browse files
committed
More release prep.
1 parent 0d7e90d commit d9fa53d

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
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

@@ -92,7 +99,7 @@ npm install && npm test
9299

93100
## Changelog
94101

95-
### 3.0.0
102+
### main
96103
- Changed module structure. When using bundlers that import the es module even using require() the import might need to be updated.
97104
- Dependency update
98105
- Setting sideEffects: false in package.json
@@ -139,12 +146,12 @@ you will need to use a polyfill like [typedarray.js](http://www.calormen.com/pol
139146

140147

141148
## License
142-
Copyright (c) 2015 Jonas Wagner, licensed under the MIT License (enclosed)
149+
Copyright (c) 2021 Jonas Wagner, licensed under the MIT License (enclosed)
143150

144151
## Credits
145152
This is mostly a direct javascript port of the [Java implementation](http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java)
146153
by Stefan Gustavson and Peter Eastman.
147154

148155
The integrated pseudo random generator is based on code by by Johannes Baagøe.
149156

150-
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).

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
"start": "parcel test/visual.html",
7373
"test": "eslint simplex-noise.ts && mocha && ./test/module-compatibility.sh",
7474
"build": "./build.sh",
75-
"docs": "typedoc --out public/docs simplex-noise.ts",
75+
"docs": "typedoc --excludePrivate --out public/docs simplex-noise.ts",
7676
"prepare": "npm run-script build",
7777
"benchmark": "parcel build && node ./perf/benchmark.js"
7878
}
79-
}
79+
}

release-docs.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
npm run-scripts docs
3+
rsync -rv public/ x.29a.ch:/var/www/static/simplex-noise/

simplex-noise.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ const grad4 = new Float32Array([0, 1, 1, 1, 0, 1, 1, -1, 0, 1, -1, 1, 0, 1, -1,
5959
1, 1, 1, 0, 1, 1, -1, 0, 1, -1, 1, 0, 1, -1, -1, 0,
6060
-1, 1, 1, 0, -1, 1, -1, 0, -1, -1, 1, 0, -1, -1, -1, 0]);
6161

62-
type RandomFn = () => number;
62+
/**
63+
* A random() function, must return a numer in the interval [0,1), just like Math.random().
64+
*/
65+
export type RandomFn = () => number;
6366

6467
/** Deterministic simplex noise generator suitable for 2D, 3D and 4D spaces. */
6568
export class SimplexNoise {
@@ -68,7 +71,7 @@ export class SimplexNoise {
6871
private permMod12: Uint8Array;
6972
/**
7073
* Creates a new `SimplexNoise` instance.
71-
* This involves some setup costs so should preferably only be called once.
74+
* This involves some setup. You can save a few cpu cycles by reusing the same instance.
7275
* @param randomOrSeed A random number generator or a seed (string|number).
7376
* Defaults to Math.random (random irreproducible initialization).
7477
*/
@@ -83,6 +86,12 @@ export class SimplexNoise {
8386
}
8487
}
8588

89+
/**
90+
* Samples the noise field in 2 dimensions
91+
* @param x
92+
* @param y
93+
* @returns a number in the interval [-1, 1]
94+
*/
8695
noise2D(x: number, y: number): number {
8796
const permMod12 = this.permMod12;
8897
const perm = this.perm;
@@ -142,7 +151,14 @@ export class SimplexNoise {
142151
// The result is scaled to return values in the interval [-1,1].
143152
return 70.0 * (n0 + n1 + n2);
144153
}
145-
// 3D simplex noise
154+
155+
/**
156+
* Samples the noise field in 3 dimensions
157+
* @param x
158+
* @param y
159+
* @param z
160+
* @returns a number in the interval [-1, 1]
161+
*/
146162
noise3D(x:number, y:number, z:number): number {
147163
const permMod12 = this.permMod12;
148164
const perm = this.perm;
@@ -265,7 +281,14 @@ export class SimplexNoise {
265281
// The result is scaled to stay just inside [-1,1]
266282
return 32.0 * (n0 + n1 + n2 + n3);
267283
}
268-
// 4D simplex noise, better simplex rank ordering method 2012-03-09
284+
285+
/**
286+
* Samples the noise field in 4 dimensions
287+
* @param x
288+
* @param y
289+
* @param z
290+
* @returns a number in the interval [-1, 1]
291+
*/
269292
noise4D(x:number, y:number, z:number, w:number): number {
270293
const perm = this.perm;
271294

@@ -395,6 +418,9 @@ export class SimplexNoise {
395418
export default SimplexNoise;
396419

397420
/**
421+
* Builds a random permutation table.
422+
* This is exported only for (internal) testing purposes.
423+
* Do not rely on this export.
398424
* @private
399425
*/
400426
export function buildPermutationTable(random: RandomFn): Uint8Array {

test/visual.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
<body>
44
<h1>simplex-noise.js visual tests</h1>
5+
<!-- open me using npx parcel test/visual.html -->
56
<script type="module" src="visual.ts" />
67
</body>

0 commit comments

Comments
 (0)