Noisette
A library for generating 2D noise functions with analytical gradients.
Usage
This crate provides a simple API for creating Noise objects which can be sampled within the unit square for both their value and analytical gradient.
let mut rng = thread_rng;
let noise = new;
let value = noise.sample;
let gradient = noise.gradient;
Stacks
You can stack multiple weighted noise functions together into a single noise function using the Stack struct:
let noise = new;
The GradientFunction enum can be used to apply an additional weighting to the sampled value of each noise function influenced by the magnitude of the current gradient.
This can be can be useful for creating effects such as ridges or terraces.
The Noop variant does not apply any additional weighting.
Gradient Functions
Noop: No change in weighting.Inverse: 1/(1 + k * x).Exp: exp(-(scale * x)^2).Sigmoid: 1/(1 + exp(-k * x)).Tanh: (tanh(k * x) + 1) / 2.Cosine: 0.5 * (cos(frequency * x) + 1).Quadratic: 1/(1 + k * x^2).Arctan: (atan(k * x) / pi + 0.5).
Features
Left: Each of the images below show the sampled noise function over the unit square, tiled 2 times in each direction to show the periodicity of the noise.
Right: The magnitude of the gradient of the noise function scaled to the range [0, 1].
Top: A single noise function.
Bottom: A stack of multiple noise functions with different weights.
Perlin Noise


Simplex Noise


OpenSimplex Noise


Note: Simplex noise is inherently not tileable, however the OpenSimplex implementation is tileable (by using 4D space).
Worley Noise


Note: The gradient of the Worley noise can not be determined analytically, so the gradient is approximated using central differences.
Examples
You can run the examples to generate images of the noise functions.
First, clone the repository and set the current directory to the root of the repository:
Make sure to create the ./output directory for the images to be saved to:
Then, build the examples:
And run the example you want to generate an image. For example, to generate an image of stacked Simplex noise: