1.0.0 • Published 10 years ago
noise3d v1.0.0
noise3d
Install
npm install noise3dUsage
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(x / 64, y / 64, z) * 128;
}
}Noise functions
All noise functions implement following interface:
value = noise(x, y, z)xx coordinateyy coordinatezz coordinatevaluenoise 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.interpolationinterpolation method (see utility methods)params.permutationpermutation array (numbers 0 to 255 in pseudorandom order)
noise.createCheckerboard(params)
Checkerboard Pattern
var checker = noise.createCheckerboard({
interpolation: noise.interpolation.nearestNeighbour,
size: 2
});params.interpolationinterpolation method (see utility methods)params.sizesize between checkerboard rectangles
noise.createConstant(params)
Constant Value
var constant = noise.createConstant({
value: 0.3
});params.valueconstant value between -1, +1
noise.createInverter(params)
Inverts noise values
var invert = noise.createInverter({
noise: perlin
});params.noisethe noise function (x, y, z) to invert
noise.createBrownianMotion
Fractal Brownian Motion
var brownian = noise.createBrownianMotion({
octaves: 4,
persistence: 0.5,
noise: perlin
});params.octavesnumber of octavesparams.persistencepersistence (amplitude)params.noiseinput 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)arraythe array to be shuffledrandoma random function that generates numbers between [0, 1)
1.0.0
10 years ago