npm

Need private packages and team management tools?Check out npm Orgs. »

noise3d

1.0.0 • Public • Published

noise3d

Install

npm install noise3d

Usage

var noise = require("noise3d");
 
var perlin = noise.createPerlin({
    interpolation: noise.interpolation.linear,
    permutation: noise.array.shuffle(noise.array.range(0, 255), Math.random)
});
 
var brownian = noise.createBrownianMotion({
    octaves: 4,
    persistence: 0.5,
    noise: perlin
});
 
for (var x = 0; x < 512; x++) {
    for (var y = 0; y < 512; y++) {
        var z = 1; // keep z constant for 2D noise
        image[x][y] = 127 + brownian(/ 64, y / 64, z) * 128;
    }
}

Noise functions

All noise functions implement following interface:

value = noise(x, y, z)
  • x x coordinate
  • y y coordinate
  • z z coordinate
  • value noise value between [-1, +1]

noise.createPerlin(params)

Perlin Noise

var perlin = noise.createPerlin({
    interpolation: noise.interpolation.linear,
    permutation: noise.array.shuffle(noise.array.range(0, 255), Math.random)
});
  • params.interpolation interpolation method (see utility methods)
  • params.permutation permutation array (numbers 0 to 255 in pseudorandom order)

noise.createCheckerboard(params)

Checkerboard Pattern

var checker = noise.createCheckerboard({
    interpolation: noise.interpolation.nearestNeighbour,
    size: 2
});
  • params.interpolation interpolation method (see utility methods)
  • params.size size between checkerboard rectangles

noise.createConstant(params)

Constant Value

var constant = noise.createConstant({
    value: 0.3
});
  • params.value constant value between [-1, +1]

noise.createInverter(params)

Inverts noise values

var invert = noise.createInverter({
    noise: perlin
});
  • params.noise the noise function (x, y, z) to invert

noise.createBrownianMotion

Fractal Brownian Motion

var brownian = noise.createBrownianMotion({
    octaves: 4,
    persistence: 0.5,
    noise: perlin
});
  • params.octaves number of octaves
  • params.persistence persistence (amplitude)
  • params.noise input noise function to fractionally combine

Utility methods

Interpolation

All interpolation methods implement following interface:

value = interpolate(a, b, t)
  • noise.interpolation.nearestNeighbour
  • noise.interpolation.linear
  • noise.interpolation.cosine

noise.array.range(a, b)

Create an array with items between a and b

noise.array.range(3, 5) == [3, 4, 5]

noise.array.shuffle(array, random)

Shuffle an array

noise.array.shuffle([3, 4, 5], Math.random)
  • array the array to be shuffled
  • random a random function that generates numbers between [0, 1)

install

npm i noise3d

Downloadsweekly downloads

2

version

1.0.0

license

WTFPL

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability