8 releases (3 stable)
1.1.0 | Dec 14, 2018 |
---|---|
1.0.1 | Jan 18, 2018 |
1.0.0 | Sep 11, 2016 |
0.1.1 | Apr 16, 2016 |
0.0.1 | Dec 27, 2014 |
#2101 in Algorithms
11KB
147 lines
Cellular Map
What is it?
Cellular Map is a simple implementation of a procedural map generator in Rust. It uses the Cellular Automata technique in order to create structures similar to caves or natural environments.
An Example
##################################################
####.....###...###...#############################
###.......#...........#..#########################
###.......................##################...###
###........................################.....##
####........................##############.......#
#####.................#.....##############.......#
######...............###....########..####......##
######...............####..########.....##.....###
######..............##############............####
#######..###......################.............###
#############.....#########..######............###
#############.....#######.....######...........###
##############...#######........####...##......###
#############.....#####..........####..##.......##
##########.......................####............#
#########........................###.............#
#########...........##............##............##
########............##..........................##
######..........................................##
#####...........................................##
#####..........................#.........####..###
######........................###.......######..##
#######.....................#####.......#####....#
######......................####.........#.......#
######...........................................#
######..........##..................##...........#
#####....#####..##.................###...........#
###.....######...##...#............##...........##
##......#####....########......................###
#.......####......########..##..................##
#........###......########..##...................#
#........###......########.......................#
##.........#.......######......#.................#
##..........#......######.....###...............##
#..........###.....######.....####..............##
#..........##.......######.....###...............#
##.........##........######.....###.....##.......#
###...................#####......###...###......##
####...................#####.....###....#.......##
####....................######.................###
###......................#####...............#####
###................##....###......##........######
##................###.............###......#######
##...............####.............####....########
###..............#####............######..########
#######...#......########.........################
############.....#########....#..#################
##############..###########..#####################
##################################################
Usage
The usage for the class is shown in the example main provided in the source:
extern crate cellular_maps;
use cellular_maps::CellularMap;
fn main() {
let mut cm = CellularMap::new(30u,30u);
cm.random_fill(40u);
print_map(&cm);
cm.evolve();
cm.evolve();
cm.evolve();
print_map(&cm);
}
Easy. The result is stored in the class and can be accessed how shown in the print function.
fn print_map(map: &CellularMap) {
let mut res_string = "".to_string();
for c in range(0u,(map.get_width())) {
for r in range(0u,map.get_height()) {
if map.get_element(r,c) == 0 {
res_string.push_str(".");
} else if map.get_element(r,c) == 1 {
res_string.push_str("#");
} else {
res_string.push_str("@")
}
}
res_string.push_str("\n");
}
println!("{}",res_string);
}
Running the Example
You can run the basic example with the command:
cargo run --example base
Dependencies
~330–520KB