Links
Getting Started
Using FastNoise with npm
To begin install the npm package fastnose-lite with
Note FastNoise does not support the node.js require(''); function. Instead, enable ES6 modules and import.
import FastNoise from "fastnoise-lite";
let noise = new FastNoise();
Creating a 128x128 Array of OpenSimplex2 Noise
// Create and configure FastNoise object
let noise = new NoiseLite();
noise.SetNoiseType(FastNoise.NoiseType.OpenSimplex2);
// Gather noise data
let noiseData = [];
for (let y= 0; y < 128; y++) {
for (let x= 0; x < 128; x++) {
if (typeof noiseData[x] == 'undefined']){
noiseData[x] = [];
}
noiseData[x][y] = noise.GetNoise(x,y);
}
}
// Do something with this data...
Internal Method Overloading
Since JavaScript does not support method overloading it has been simulated to make the user experience more continuous between language versions.
Some of the code has been changed to use switch statments since it provided a minor preformance boost in some small frequently used places eg the _Hash methods.
Here is a template for the method overloading:
class FastNoise {
/**
* JSdoc
*/
Method() {
let R2 = (Param1, Param2) => {
//do something 2D
}
let R3 = (Param1, Param2, Param3) => {
//do something 3D
}
if (arguments.lenght === 2) {
return R2(arguments[0], arguments[1]);
}
if (arguments.length === 3) {
return R3(arguments[0], arguments[1], arguments[2])
}
}
}