Skip to content

Commit

Permalink
More release prep.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwagner committed Aug 22, 2021
1 parent 0d7e90d commit d9fa53d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# simplex-noise.js
[![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)

simplex-noise.js is a fast simplex noise implementation in Javascript. It works in the browser and on nodejs.
[API Documentation](https://29a.ch/simplex-noise/docs/classes/SimplexNoise.html)

[![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/)


simplex-noise.js is a simplex noise implementation in Javascript/TypeScript.
It works in the browser and nodejs. Using Commonjs and ES Modules.
It is self contained (dependency free), relatively small (about 2k minified and gzipped)
and fairly fast (about 20 nanoseconds for a sample of 2d noise).

## Demos

Expand Down Expand Up @@ -92,7 +99,7 @@ npm install && npm test

## Changelog

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


## License
Copyright (c) 2015 Jonas Wagner, licensed under the MIT License (enclosed)
Copyright (c) 2021 Jonas Wagner, licensed under the MIT License (enclosed)

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

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

The typescript definition has been provided by [Neonit](https://github.com/Neonit).
The initial typescript definition has been provided by [Neonit](https://github.com/Neonit).
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
"start": "parcel test/visual.html",
"test": "eslint simplex-noise.ts && mocha && ./test/module-compatibility.sh",
"build": "./build.sh",
"docs": "typedoc --out public/docs simplex-noise.ts",
"docs": "typedoc --excludePrivate --out public/docs simplex-noise.ts",
"prepare": "npm run-script build",
"benchmark": "parcel build && node ./perf/benchmark.js"
}
}
}
3 changes: 3 additions & 0 deletions release-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
npm run-scripts docs
rsync -rv public/ x.29a.ch:/var/www/static/simplex-noise/
34 changes: 30 additions & 4 deletions simplex-noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const grad4 = new Float32Array([0, 1, 1, 1, 0, 1, 1, -1, 0, 1, -1, 1, 0, 1, -1,
1, 1, 1, 0, 1, 1, -1, 0, 1, -1, 1, 0, 1, -1, -1, 0,
-1, 1, 1, 0, -1, 1, -1, 0, -1, -1, 1, 0, -1, -1, -1, 0]);

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

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

/**
* Samples the noise field in 2 dimensions
* @param x
* @param y
* @returns a number in the interval [-1, 1]
*/
noise2D(x: number, y: number): number {
const permMod12 = this.permMod12;
const perm = this.perm;
Expand Down Expand Up @@ -142,7 +151,14 @@ export class SimplexNoise {
// The result is scaled to return values in the interval [-1,1].
return 70.0 * (n0 + n1 + n2);
}
// 3D simplex noise

/**
* Samples the noise field in 3 dimensions
* @param x
* @param y
* @param z
* @returns a number in the interval [-1, 1]
*/
noise3D(x:number, y:number, z:number): number {
const permMod12 = this.permMod12;
const perm = this.perm;
Expand Down Expand Up @@ -265,7 +281,14 @@ export class SimplexNoise {
// The result is scaled to stay just inside [-1,1]
return 32.0 * (n0 + n1 + n2 + n3);
}
// 4D simplex noise, better simplex rank ordering method 2012-03-09

/**
* Samples the noise field in 4 dimensions
* @param x
* @param y
* @param z
* @returns a number in the interval [-1, 1]
*/
noise4D(x:number, y:number, z:number, w:number): number {
const perm = this.perm;

Expand Down Expand Up @@ -395,6 +418,9 @@ export class SimplexNoise {
export default SimplexNoise;

/**
* Builds a random permutation table.
* This is exported only for (internal) testing purposes.
* Do not rely on this export.
* @private
*/
export function buildPermutationTable(random: RandomFn): Uint8Array {
Expand Down
1 change: 1 addition & 0 deletions test/visual.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

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

0 comments on commit d9fa53d

Please sign in to comment.