Skip to content

WesleyClements/asm-noise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asm-noise

npm version

An implementation of noise algorithms in asm.js. Due to asm.js being deprecated, this package has no advantages to native JavaScript code. Check out simplex-noise!

Table of Contents

  1. Installation
  2. Usage
  3. Options
  4. Roadmap
  5. Contributing
  6. Acknowledgments
  7. License

Using npm:

npm install asm-noise

Using unpkg CDN:

<script src="https://unpkg.com/asm-noise"></script>

Supports both CommonJS and ES Modules.

var noise = require('asm-noise');
import noise from 'asm-noise';

When linked directly in HTML using CDN, functionality is exposed globally through window.noise .

<script src="https://unpkg.com/asm-noise"></script>

Generate noise:

var value2D = noise(0.1, 0.2);
var value3D = noise(0.1, 0.2, 0.3);
var value4D = noise(0.1, 0.2, 0.3, 0.4);

Noise generation options can be set directly

noise.algorithm = 'open-simplex';
noise.seed = Date.now();
noise.octaves = 8;
noise.lacunarity = (1 + Math.sqrt(5)) / 2;
noise.persistence = (Math.sqrt(5) - 1) / 2;
noise.offset = {
  x: (5393 * (1 + Math.sqrt(5))) / 2,
  y: (4691 * (1 + Math.sqrt(5))) / 2,
  z: (10093 * (1 + Math.sqrt(5))) / 2,
  w: (9241 * (1 + Math.sqrt(5))) / 2,
};

or by passing an options object to noise.config

noise.config({ ...options... });

algorithm

Type: String

Noise generation algorithm to be used. Possible values: open-simplex, perlin

Default: 'open-simplex'

seed

Type: Number

Default: 'open-simplex'

Value used to seed the internal state of the current noise generation algorithm.

Default: Date.now()

octaves

Type: Number

Number of itterations of noise to sum together when generating noise at single point.

Default: 8

lacunarity

Type: Number

On the nth generation itteration, the generation point is scaled by this value raised to the nth power.

Default: (1 + Math.sqrt(5)) / 2

persistence

Type: Number

On the nth generation itteration, the nth noise value is scaled by this value raised to the nth power.

Default: (Math.sqrt(5) - 1) / 2

offset

Type: { x: Number; y: Number; z: Number; w: Number; }

Contains axis specific values to add to the generation point every generation itteration.

Default:

{
  x: (5393 * (1 + Math.sqrt(5))) / 2,
  y: (4691 * (1 + Math.sqrt(5))) / 2,
  z: (10093 * (1 + Math.sqrt(5))) / 2,
  w: (9241 * (1 + Math.sqrt(5))) / 2,
}
  • Improve performance of algorithm implementations
  • Implement additional algorithms
  • Add batch generation

Pull requests are welcome.

To implement a new noise generation algorithm:

  1. Create a file in the src directory with the name of the algorithm.
  2. This file should be an ES Module.
  3. The deafult export of this file should be an object with following properties:
  • seed: number;
  • noise2D: function(octaves, lacunarity, persistence, xOffset, yOffset, x, y) => number
  • noise3D: function(octaves, lacunarity, persistence, xOffset, yOffset, zOffset, x, y, z) => number
  • noise4D: function(octaves, lacunarity, persistence, xOffset, yOffset, zOffset, wOffset, x, y, z, w) => number

Many thanks to @KdotJPG for the creation of OpenSimplex noise algorithm.

This project is licensed under the terms of the MIT license.

Releases

No releases published

Packages

No packages published