Struct noise_functions::NoiseFn

source ·
pub struct NoiseFn<F>(pub F);
Expand description

Wraps a function to make it implement Sample.

The function is expected to take one parameter for the position and optionally a seed parameter.

With a seed parameter it can be used for fractals:

use noise_functions::{ NoiseFn, Sample2, OpenSimplex2s };

let warped = NoiseFn(|pos: [f32; 2], seed: i32| {
    let warp_x = OpenSimplex2s.seed(seed + 100).sample2(pos);
    let warp_y = OpenSimplex2s.seed(seed + 200).sample2(pos);
    let warped = [pos[0] + warp_x, pos[1] + warp_y];
    OpenSimplex2s.sample2(warped)
});

let warped_fbm = warped.fbm(3, 0.5, 2.0);

let value = warped_fbm.sample2([1.0, 2.0]);

Tuple Fields§

§0: F

Implementations§

source§

impl<F> NoiseFn<F>

source

pub const fn seed(self, seed: i32) -> Seeded<Self>

source

pub const fn frequency(self, frequency: f32) -> Frequency<Self>

source

pub const fn fbm(self, octaves: u32, gain: f32, lacunarity: f32) -> Fbm<Self>

This function is const if the feature nightly-const-fn-float is enabled.

source

pub const fn fbm_weighted( self, octaves: u32, gain: f32, lacunarity: f32, weighted_strength: f32 ) -> FbmWeighted<Self>

This function is const if the feature nightly-const-fn-float is enabled.

source

pub const fn ridged( self, octaves: u32, gain: f32, lacunarity: f32 ) -> Ridged<Self>

This function is const if the feature nightly-const-fn-float is enabled.

source

pub const fn ridged_weighted( self, octaves: u32, gain: f32, lacunarity: f32, weighted_strength: f32 ) -> RidgedWeighted<Self>

This function is const if the feature nightly-const-fn-float is enabled.

source

pub const fn ping_pong( self, octaves: u32, gain: f32, lacunarity: f32, strength: f32 ) -> PingPong<Self>

This function is const if the feature nightly-const-fn-float is enabled.

source

pub const fn ping_pong_weighted( self, octaves: u32, gain: f32, lacunarity: f32, strength: f32, weighted_strength: f32 ) -> PingPongWeighted<Self>

This function is const if the feature nightly-const-fn-float is enabled.

Trait Implementations§

source§

impl<const DIM: usize, Pos, F> Sample<DIM, Pos> for NoiseFn<F>
where F: Fn(Pos) -> f32,

source§

fn sample(&self, pos: Pos) -> f32

Auto Trait Implementations§

§

impl<F> Freeze for NoiseFn<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for NoiseFn<F>
where F: RefUnwindSafe,

§

impl<F> Send for NoiseFn<F>
where F: Send,

§

impl<F> Sync for NoiseFn<F>
where F: Sync,

§

impl<F> Unpin for NoiseFn<F>
where F: Unpin,

§

impl<F> UnwindSafe for NoiseFn<F>
where F: UnwindSafe,

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<Noise> Sample2 for Noise
where Noise: Sample<2>,

source§

fn sample2(&self, pos: impl Into<[f32; 2]>) -> f32

source§

impl<Noise> Sample2a for Noise
where Noise: Sample<2, Simd<f32, 2>>,

source§

fn sample2a(&self, pos: impl Into<Simd<f32, 2>>) -> f32

Available on crate feature nightly-simd only.
source§

impl<Noise> Sample3 for Noise
where Noise: Sample<3>,

source§

fn sample3(&self, pos: impl Into<[f32; 3]>) -> f32

source§

impl<Noise> Sample3a for Noise
where Noise: Sample<3, Simd<f32, 4>>,

source§

fn sample3a(&self, pos: impl Into<Simd<f32, 4>>) -> f32

Available on crate feature nightly-simd only.
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.