[][src]Struct procedural_generation::Generator

pub struct Generator {
    pub map: Vec<usize>,
    pub width: usize,
    pub height: usize,
    pub noise_options: NoiseOptions,
    // some fields omitted
}

The foundation of this crate

Fields

map: Vec<usize>width: usizeheight: usizenoise_options: NoiseOptions

Implementations

impl Generator[src]

pub fn new() -> Self[src]

Create generator.

pub fn with_seed(self, seed: u32) -> Self[src]

Set seed for noise generation. Useful for reproducing results. Random otherwise.

pub fn with_options(self, options: NoiseOptions) -> Self[src]

Changes how noise is generated. Different values make for much more interesting noise

pub fn show(&self)[src]

Prints the map to stdout with colors.

pub fn with_size(self, width: usize, height: usize) -> Self[src]

Sets size of map. This clears the map as well.

pub fn spawn_perlin<F: Fn(f64) -> usize + Sync>(self, f: F) -> Self[src]

Generates perlin noise over the entire map. For every coordinate, the closure f(f64) receives a value between 0 and 1. This closure must then return a usize accordingly to what value it receives, such as the following. You can also modify some options for how the noise should behave, see NoiseOptions.

fn main() {
    Generator::new()
        .with_size(40, 20)
        .spawn_perlin(|value| {
            if value > 0.66 {
                2
            } else if value > 0.33 {
                1
            } else {
                0
            }
        })
        .show();
}

pub fn spawn_rooms(self, number: usize, rooms: usize, size: &Size) -> Self[src]

Spawns rooms of varying sizes based on input size. number sets what number the rooms are represented with in the map, rooms is amount of rooms to generate and size specifies the minimum and maximum boundaries for each room.

fn main() {
    let size = Size::new((4, 4), (10, 10));
    Generator::new()
        .with_size(30, 20)
        .spawn_rooms(2, 3, &size)
        .show();
}

pub fn get(&self, x: usize, y: usize) -> usize[src]

Returns value at (x, y) coordinate, useful since map is in 1d form but treated as 2d.

pub fn set(&mut self, x: usize, y: usize, value: usize)[src]

Same as get(...), except sets value.

pub fn get_2d_map(&self) -> Vec<Vec<usize>>[src]

This is not recommended unless it's convenient or necessary, as 2d vectors are slow.

Trait Implementations

impl Debug for Generator[src]

impl Default for Generator[src]

impl Display for Generator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<D> OwoColorize for D[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,