Struct fuss::Simplex

source ·
pub struct Simplex {
    pub seed: Vec<usize>,
    /* private fields */
}
Expand description

Hold the proper permutation tables and methods for generating 2D and 3D noise.

It is intended for you to get a Simplex through Simplex::new() since that creates the necessary permutation tables needed to generate noise.

Noise generated by Simplex is random every time.

  • seed - Seed that will be used by Simplex to generate it’s permutation table

Fields

seed: Vec<usize>

Implementations

Return a new Simplex with a new random permutation table

Necessary to generate the proper permutation tables (GRAD3) used by noise_2d() and noise_3d.

Examples
use fuss::Simplex;
 
let sn = Simplex::new();

Seed the random number generator with a specific seed

A seed is just a vector of usizes that will be passed into StdRng::from_seed as a slice.

Examples
use fuss::Simplex;
 
let mut sn = Simplex::from_seed(vec![1, 2, 3]);
let mut other_sn = Simplex::from_seed(vec![1, 2, 3]);
 
assert_eq!(other_sn.noise_2d(1.0, 14.2), sn.noise_2d(1.0, 14.2));
assert_eq!(other_sn.noise_3d(1.0, 14.2, -5.4), sn.noise_3d(1.0, 14.2, -5.4));
 
sn = Simplex::from_seed(vec![4, 5, 6]);
let mut other_sn = Simplex::from_seed(vec![1, 2, 3]);
assert!(other_sn.noise_2d(1.0, 14.2) != sn.noise_2d(1.0, 14.2));
assert!(other_sn.noise_3d(1.0, 14.2, -5.4) != sn.noise_3d(1.0, 14.2, -5.4));

Smooth the output from noise_2d based on fractal Brownian motion.

Returns an f32 in [-1, 1]

Examples
use fuss::Simplex;
 
let sn = Simplex::new();
 
let mut luminance = Vec::<Vec<f32>>::new();
for x in 0..100 {
  luminance.push(Vec::<f32>::new());
  for y in 0..100 {
    luminance[x as usize].push(sn.sum_octave_2d(16, x as f32, y as f32, 0.5, 0.008));
  }
}

Smooth the output from noise_3d based on fractal Brownian motion.

Returns an f32 in [-1, 1]

Examples
use fuss::Simplex;
 
let sn = Simplex::new();
 
let mut luminance = Vec::<Vec<Vec<f32>>>::new();
for x in 0..10 {
  luminance.push(Vec::<Vec<f32>>::new());
  for y in 0..10 {
    luminance[x as usize].push(Vec::<f32>::new());
    for z in 0..10 {
      luminance[x as usize][y as usize].push(sn.sum_octave_3d(16, x as f32, y as f32, z as f32, 0.5, 0.008));
    }
  }
}

Generate 2D simplex noise for a specific point

Returns an f32 in [-1, 1].

Examples
use fuss::Simplex;
 
let sn = Simplex::from_seed(vec![5, 3, 2, 1, 1]);
println!("{}", sn.noise_2d(50.1912, 30.50102));
 
// Simplex will return the same thing for the same points
assert_eq!(sn.noise_2d(1.5, -0.5), sn.noise_2d(1.5, -0.5));
 
let other_sn = Simplex::from_seed(vec![0, 1, 2, 3, 4, 5]);
 
// However each `Simplex` has it's own set of permutations, therefore
// each one is different. If you want consistency, try the `from_seed()` method.
assert!(sn.noise_2d(1.5, -0.5) != other_sn.noise_2d(1.5, -0.5));

Generate 3D simplex noise for a specific point

Returns an f32 in [-1, 1].

Examples
use fuss::Simplex;
 
let sn = Simplex::new();
println!("{}", sn.noise_2d(50.1912, 30.50102));
 
// Simplex will return the same thing for the same points
assert_eq!(sn.noise_3d(1.5, -0.5, 2.1), sn.noise_3d(1.5, -0.5, 2.1));
 
let other_sn = Simplex::new();
 
// However each `Simplex` has it's own set of permutations, therefore
// each one is different. If you want consistency, try the `from_seed()` method.
assert!(sn.noise_3d(1.5, -0.5, 2.1) != other_sn.noise_3d(1.5, -0.5, 2.1));

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.