pub struct FastNoiseLite {
Show 15 fields pub seed: i32, pub frequency: f32, pub noise_type: NoiseType, pub rotation_type_3d: RotationType3D, pub fractal_type: FractalType, pub octaves: i32, pub lacunarity: f32, pub gain: f32, pub weighted_strength: f32, pub ping_pong_strength: f32, pub cellular_distance_function: CellularDistanceFunction, pub cellular_return_type: CellularReturnType, pub cellular_jitter_modifier: f32, pub domain_warp_type: DomainWarpType, pub domain_warp_amp: f32, /* private fields */
}
Expand description

The object you construct, configure, and then use to sample the noise.

  1. Construct this with FastNoiseLite::new or FastNoiseLite::with_seed.
  2. Configure it from its defaults with the various set_* functions.
  3. Optionally, use FastNoiseLite::domain_warp_2d or FastNoiseLite::domain_warp_3d to translate the input coordinates to their warped positions.
  4. Use FastNoiseLite::get_noise_2d or FastNoiseLite::get_noise_3d to sample the noise at the (ordinary or warped) input coordinates.

§Example

use fastnoise_lite::*;
 
// Create and configure the FastNoise object
let mut noise = FastNoiseLite::new();
noise.set_noise_type(Some(NoiseType::OpenSimplex2));
 
const WIDTH: usize = 128;
const HEIGHT: usize = 128;
let mut noise_data = [[0.; HEIGHT]; WIDTH];
 
// Sample noise pixels
for x in 0..WIDTH {
    for y in 0..HEIGHT {
        // Domain warp can optionally be employed to transform the coordinates before sampling:
        // let (x, y) = noise.domain_warp_2d(x as f32, y as f32);
         
        let negative_1_to_1 = noise.get_noise_2d(x as f32, y as f32);
        // You may want to remap the -1..1 range data to the 0..1 range:
        noise_data[x][y] = (neg_1_to_1 + 1.) / 2.;
         
        // (Uses of `as f32` above should become `as f64` if you're using FNL with the "f64" feature flag)
    }
}

// Do something with this data...

Fields§

§seed: i32§frequency: f32§noise_type: NoiseType§rotation_type_3d: RotationType3D§fractal_type: FractalType§octaves: i32§lacunarity: f32§gain: f32§weighted_strength: f32§ping_pong_strength: f32§cellular_distance_function: CellularDistanceFunction§cellular_return_type: CellularReturnType§cellular_jitter_modifier: f32§domain_warp_type: DomainWarpType§domain_warp_amp: f32

Implementations§

source§

impl FastNoiseLite

source

pub fn new() -> Self

§Constructor

Create new FastNoise object with the default seed of 1337.

source

pub fn with_seed(seed: i32) -> Self

Create new FastNoise object with a specific seed.

source

pub fn set_seed(&mut self, seed: Option<i32>)

Sets seed used for all noise types.

If set to None, it is reset to its default: 1337.

source

pub fn set_frequency(&mut self, frequency: Option<f32>)

Sets frequency used for all noise types.

If set to None, it is reset to its default: 0.01.

source

pub fn set_noise_type(&mut self, noise_type: Option<NoiseType>)

Sets noise algorithm used for get_noise_2d/get_noise_3d.

If set to None, it is reset to its default: NoiseType::OpenSimplex2.

source

pub fn set_rotation_type_3d(&mut self, rotation_type_3d: Option<RotationType3D>)

Sets domain rotation type for 3D Noise and 3D DomainWarp. Can aid in reducing directional artifacts when sampling a 2D plane in 3D.

If set to None, it is reset to its default: RotationType3D::None.

source

pub fn set_fractal_type(&mut self, fractal_type: Option<FractalType>)

Sets method for combining octaves in all fractal noise types.

If set to None, it is reset to its default: FractalType::None.

Note: FractalType::DomainWarpProgressive/FractalType::DomainWarpIndependent only affects domain_warp_2d.

source

pub fn set_fractal_octaves(&mut self, octaves: Option<i32>)

Sets octave count for all fractal noise types.

If set to None, it is reset to its default: 3.

source

pub fn set_fractal_lacunarity(&mut self, lacunarity: Option<f32>)

Sets octave lacunarity for all fractal noise types.

If set to None, it is reset to its default: 2.0.

source

pub fn set_fractal_gain(&mut self, gain: Option<f32>)

Sets octave gain for all fractal noise types.

If set to None, it is reset to its default: 0.5.

source

pub fn set_fractal_weighted_strength(&mut self, weighted_strength: Option<f32>)

Sets octave weighting for all none DomainWarp fractal types.

If set to None, it is reset to its default: 0.0.

Note: Keep between 0..1 to maintain -1..1 output bounding.

source

pub fn set_fractal_ping_pong_strength( &mut self, ping_pong_strength: Option<f32> )

Sets strength of the fractal ping pong effect.

If set to None, it is reset to its default: 2.0.

source

pub fn set_cellular_distance_function( &mut self, cellular_distance_function: Option<CellularDistanceFunction> )

Sets distance function used in cellular noise calculations.

If set to None, it is reset to its default: CellularDistanceFunction::EuclideanSq.

source

pub fn set_cellular_return_type( &mut self, cellular_return_type: Option<CellularReturnType> )

Sets return type from cellular noise calculations.

If set to None, it is reset to its default: CellularReturnType::Distance.

source

pub fn set_cellular_jitter(&mut self, cellular_jitter: Option<f32>)

Sets the maximum distance a cellular point can move from its grid position.

If set to None, it is reset to its default: 1.0.

Note: Setting this higher than 1 will cause artifacts.

source

pub fn set_domain_warp_type(&mut self, domain_warp_type: Option<DomainWarpType>)

Sets the warp algorithm when using domain_warp_2d.

If set to None, it is reset to its default: DomainWarpType::OpenSimplex2.

source

pub fn set_domain_warp_amp(&mut self, domain_warp_amp: Option<f32>)

Sets the maximum warp distance from original position when using domain_warp_2d.

If set to None, it is reset to its default: 1.0.

source

pub fn get_noise_2d(&self, x: f32, y: f32) -> f32

2D noise at given position using current settings.

Noise output bounded between -1..1.

Example usage:

let noise = get_noise_2d(x, y); // Value in the -1..1 range
let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
source

pub fn get_noise_3d(&self, x: f32, y: f32, z: f32) -> f32

3D noise at given position using current settings.

Noise output is bounded between -1..1.

Example usage:

let noise = get_noise_3d(x, y, z); // Value in the -1..1 range
let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
source

pub fn domain_warp_2d(&self, x: f32, y: f32) -> (f32, f32)

2D warps the input position using current domain warp settings.

Example usage:

let (x, y) = domain_warp_2d(x, y);
let noise = get_noise_2d(x, y); // Value in the -1..1 range
let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
source

pub fn domain_warp_3d(&self, x: f32, y: f32, z: f32) -> (f32, f32, f32)

3D warps the input position using current domain warp settings.

Example usage:

let (x, y, z) = domain_warp_3d(x, y, z);
let noise = get_noise_3d(x, y, z); // Value in the -1..1 range
let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range

Trait Implementations§

source§

impl Default for FastNoiseLite

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.