noise_functions

Struct NoiseFn

Source
pub struct NoiseFn<F, const WITH_SEED: bool>(pub F);
Expand description

Wraps a function to make it implement Sample.

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

With a seed parameter it can be used for fractals:

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

let warped = NoiseFn(|point: [f32; 2], seed: i32| {
    let warp_x = OpenSimplex2s.seed(seed + 100).sample2(point);
    let warp_y = OpenSimplex2s.seed(seed + 200).sample2(point);
    let warped = [point[0] + warp_x, point[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

Trait Implementations§

Source§

impl<F, const WITH_SEED: bool> Noise for NoiseFn<F, WITH_SEED>

Source§

fn seed(self, seed: i32) -> Seeded<Self>
where Self: Sized,

Source§

fn frequency(self, frequency: f32) -> Frequency<Self>
where Self: Sized,

Source§

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

Source§

fn ridged(self) -> Ridged<Self>
where Self: Sized,

Source§

fn triangle_wave(self, frequency: f32) -> TriangleWave<Self>
where Self: Sized,

Source§

fn tileable(self, width: f32, height: f32) -> Tileable<Self>
where Self: Sized,

Source§

fn mul_seed(self, value: i32) -> MulSeed<Self>
where Self: Sized,

Source§

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

Source§

fn sample(&self, point: Point) -> f32

Source§

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

Source§

fn sample(&self, point: Point) -> f32

Source§

impl<const DIM: usize, Point, F> SampleWithSeed<DIM, Point> for NoiseFn<F, true>
where F: Fn(Point, i32) -> f32,

Source§

fn sample_with_seed(&self, point: Point, seed: i32) -> f32

Auto Trait Implementations§

§

impl<F, const WITH_SEED: bool> Freeze for NoiseFn<F, WITH_SEED>
where F: Freeze,

§

impl<F, const WITH_SEED: bool> RefUnwindSafe for NoiseFn<F, WITH_SEED>
where F: RefUnwindSafe,

§

impl<F, const WITH_SEED: bool> Send for NoiseFn<F, WITH_SEED>
where F: Send,

§

impl<F, const WITH_SEED: bool> Sync for NoiseFn<F, WITH_SEED>
where F: Sync,

§

impl<F, const WITH_SEED: bool> Unpin for NoiseFn<F, WITH_SEED>
where F: Unpin,

§

impl<F, const WITH_SEED: bool> UnwindSafe for NoiseFn<F, WITH_SEED>
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<N> Sample2 for N
where N: Sample<2>,

Source§

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

Source§

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

Source§

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

Available on crate feature nightly-simd only.
Source§

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

Source§

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

Source§

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

Source§

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

Available on crate feature nightly-simd only.
Source§

impl<N> Sample4 for N
where N: Sample<4>,

Source§

fn sample4(&self, point: impl Into<[f32; 4]>) -> f32

Source§

impl<N> Sample4a for N
where N: Sample<4, Simd<f32, 4>>,

Source§

fn sample4a(&self, point: 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>,

Source§

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>,

Source§

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.