Struct fuss::Simplex
[−]
[src]
pub struct Simplex {
pub seed: Vec<usize>,
// some fields omitted
}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 bySimplexto generate it's permutation table
Fields
seed: Vec<usize>
Methods
impl Simplex[src]
fn new() -> Simplex[src]
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();
fn from_seed(seed: Vec<usize>) -> Simplex[src]
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));
fn sum_octave_2d(
&self,
num_iterations: i32,
xin: f32,
yin: f32,
persistence: f32,
scale: f32
) -> f32[src]
&self,
num_iterations: i32,
xin: f32,
yin: f32,
persistence: f32,
scale: f32
) -> f32
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)); } }
fn sum_octave_3d(
&self,
num_iterations: i32,
xin: f32,
yin: f32,
zin: f32,
persistence: f32,
scale: f32
) -> f32[src]
&self,
num_iterations: i32,
xin: f32,
yin: f32,
zin: f32,
persistence: f32,
scale: f32
) -> f32
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)); } } }
fn noise_2d(&self, xin: f32, yin: f32) -> f32[src]
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));
fn noise_3d(&self, xin: f32, yin: f32, zin: f32) -> f32[src]
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));