#maps #procedural #generation #easy

procedural-generation

Procedurally generate maps elegantly

9 releases

0.3.1 Oct 3, 2020
0.3.0 Oct 3, 2020
0.2.0 Oct 3, 2020
0.1.5 Oct 2, 2020

#1798 in Game dev

21 downloads per month

MIT license

13KB
181 lines

Procedural Generation

This is a crate for for procedurally generating maps written in Rust. It's very elegant to use and creates nice results, see the example below:

use procedural_generation::Generator;

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

Produces the following (prints with colors in terminal!):

map


lib.rs:

Utility for creating procedurally generated maps

Quick Start

use procedural_generation::Generator;

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

Produces the following (prints with colors in terminal!):

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1

Dependencies

~4.5MB
~91K SLoC