### Installing Simplex Noise via npm Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This command installs the `simplex-noise` package from npm, saving it as a dependency in your project. It's the standard way to add the library to a JavaScript or TypeScript project. ```Bash npm i -S simplex-noise ``` -------------------------------- ### Generating 2D Simplex Noise Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This example initializes a 2D noise function using `createNoise2D()` and then demonstrates how to call it with `x` and `y` coordinates to get a noise value between -1 and 1. The function uses `Math.random()` for seeding by default. ```JavaScript // initialize the noise function const noise2D = createNoise2D(); // returns a value between -1 and 1 console.log(noise2D(x, y)); ``` -------------------------------- ### Installing Alea PRNG for Seeded Noise Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This command installs the `alea` package, a pseudorandom number generator, which can be used to provide a custom seed for the simplex noise functions instead of the default `Math.random()`. ```Bash npm install -S alea ``` -------------------------------- ### Migrating Seeded Noise Initialization (3.x to 4.x) Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This example details the API changes for initializing simplex noise with a seed when upgrading from version 3.x to 4.x. It highlights the need to use a PRNG like `alea` and to pass a fresh instance of the PRNG to each `createNoise` call for compatibility with 3.x behavior when using multiple noise functions. ```JavaScript // 3.x import SimplexNoise from 'simplex-noise'; const simplex = new SimplexNoise('seed'); const value2d = simplex.noise2D(x, y); ``` ```JavaScript // 4.x // npm install -S alea import { createNoise2D } from 'simplex-noise'; import alea from 'alea'; const noise2D = createNoise2D(alea('seed')); const value2d = noise2D(x, y); ``` ```JavaScript // IMPORTANT: If you use multiple noise functions (for example 2d and 3d) // and want compatible output with 3.x you will need to pass a fresh instance // of alea to each create call. If you reuse the alea instance you will // get different outputs compared to simplex-noise 3.x. const seed = 'seed'; const noise2D = createNoise2D(alea(seed)); const noise3D = createNoise3D(alea(seed)); ``` -------------------------------- ### Generating 4D Simplex Noise Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This example initializes a 4D noise function with `createNoise4D()` and demonstrates its usage with `x`, `y`, `z`, and `w` coordinates to obtain a noise value between -1 and 1. ```JavaScript const noise4D = createNoise4D(); console.log(noise4D(x, y, z, w)); ``` -------------------------------- ### Running Simplex Noise Benchmarks Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This command executes the performance benchmark script for `simplex-noise.js`, showing the operations per second for 2D, 3D, and 4D noise generation. This provides insight into the library's performance characteristics. ```Bash $ node perf/index.js noise2D: 72,916,215 ops/sec ±1% noise3D: 47,855,199 ops/sec ±0% noise4D: 35,564,111 ops/sec ±0% ``` -------------------------------- ### Importing Noise Functions (ES Module) Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet demonstrates how to import specific noise generation functions, such as `createNoise2D`, using ES Module syntax. This is suitable for modern JavaScript environments and bundlers. ```JavaScript // import the noise functions you need import { createNoise2D } from 'simplex-noise'; ``` -------------------------------- ### Initializing Simplex Noise with a Custom Seed Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet shows how to initialize a simplex noise function with a custom seed using the `alea` PRNG. By passing a PRNG function to `createNoise2D`, you can ensure reproducible noise patterns based on the provided seed. ```JavaScript import alea from 'alea'; // create a new random function based on the seed const prng = alea('seed'); // use the seeded random function to initialize the noise function const noise2D = createNoise2D(prng); console.log(noise2D(x, y)); ``` -------------------------------- ### Emulating Simplex Noise 3.x API Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet demonstrates how to create an object that mimics the `simplex.noise2D`, `simplex.noise3D`, and `simplex.noise4D` methods from the 3.x API, allowing for easier migration or compatibility with older codebases while using the 4.x functions. ```JavaScript const simplex = { noise2D: createNoise2D(alea(seed)), noise3D: createNoise3D(alea(seed)), noise4D: createNoise4D(alea(seed)) }; ``` -------------------------------- ### Migrating Random Noise Initialization (3.x to 4.x) Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet illustrates the change in API for initializing simplex noise without a specific seed when migrating from version 3.x to 4.x. Version 4.x introduces named exports for specific noise dimensions and a functional approach. ```JavaScript // 3.x import SimplexNoise from 'simplex-noise'; const simplex = new SimplexNoise(); const value2d = simplex.noise2D(x, y); ``` ```JavaScript // 4.x // import the functions you need import { createNoise2D } from 'simplex-noise'; const noise2D = createNoise2D(); const value2d = noise2D(x, y); ``` -------------------------------- ### Requiring Noise Functions (CommonJS) Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet shows how to import noise generation functions using CommonJS `require` syntax. This method is typically used in Node.js environments. ```JavaScript // import the noise functions you need const { createNoise2D } = require('simplex-noise'); ``` -------------------------------- ### Generating 3D Simplex Noise Source: https://github.com/jwagner/simplex-noise.js/blob/main/README.md This snippet initializes a 3D noise function using `createNoise3D()` and shows how to retrieve a noise value by passing `x`, `y`, and `z` coordinates. The output is a value between -1 and 1. ```JavaScript const noise3D = createNoise3D(); console.log(noise3D(x, y, z)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.