Struct fastnoise_lite::FastNoiseLite
source · 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.
- Construct this with
FastNoiseLite::new
orFastNoiseLite::with_seed
. - Configure it from its defaults with the various
set_*
functions. - Optionally, use
FastNoiseLite::domain_warp_2d
orFastNoiseLite::domain_warp_3d
to translate the input coordinates to their warped positions. - Use
FastNoiseLite::get_noise_2d
orFastNoiseLite::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
impl FastNoiseLite
sourcepub fn set_seed(&mut self, seed: Option<i32>)
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
.
sourcepub fn set_frequency(&mut self, frequency: Option<f32>)
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
.
sourcepub fn set_noise_type(&mut self, noise_type: Option<NoiseType>)
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
.
sourcepub fn set_rotation_type_3d(&mut self, rotation_type_3d: Option<RotationType3D>)
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
.
sourcepub fn set_fractal_type(&mut self, fractal_type: Option<FractalType>)
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
.
sourcepub fn set_fractal_octaves(&mut self, octaves: Option<i32>)
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
.
sourcepub fn set_fractal_lacunarity(&mut self, lacunarity: Option<f32>)
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
.
sourcepub fn set_fractal_gain(&mut self, gain: Option<f32>)
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
.
sourcepub fn set_fractal_weighted_strength(&mut self, weighted_strength: Option<f32>)
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.
sourcepub fn set_fractal_ping_pong_strength(
&mut self,
ping_pong_strength: Option<f32>
)
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
.
sourcepub fn set_cellular_distance_function(
&mut self,
cellular_distance_function: Option<CellularDistanceFunction>
)
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
.
sourcepub fn set_cellular_return_type(
&mut self,
cellular_return_type: Option<CellularReturnType>
)
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
.
sourcepub fn set_cellular_jitter(&mut self, cellular_jitter: Option<f32>)
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.
sourcepub fn set_domain_warp_type(&mut self, domain_warp_type: Option<DomainWarpType>)
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
.
sourcepub fn set_domain_warp_amp(&mut self, domain_warp_amp: Option<f32>)
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
.
sourcepub fn get_noise_2d(&self, x: f32, y: f32) -> f32
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
sourcepub fn get_noise_3d(&self, x: f32, y: f32, z: f32) -> f32
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
sourcepub fn domain_warp_2d(&self, x: f32, y: f32) -> (f32, f32)
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
sourcepub fn domain_warp_3d(&self, x: f32, y: f32, z: f32) -> (f32, f32, f32)
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