8个版本 (3个稳定版)
1.1.0 | 2018年12月14日 |
---|---|
1.0.1 | 2018年1月18日 |
1.0.0 | 2016年9月11日 |
0.1.1 | 2016年4月16日 |
0.0.1 | 2014年12月27日 |
#1591 in 算法
每月21次下载
11KB
147 行
细胞地图 
是什么?
细胞地图 是一个简单的程序化地图生成器实现,使用 Rust 编写。它使用 细胞自动机 技术来创建类似于洞穴或自然环境的结构。
示例
##################################################
####.....###...###...#############################
###.......#...........#..#########################
###.......................##################...###
###........................################.....##
####........................##############.......#
#####.................#.....##############.......#
######...............###....########..####......##
######...............####..########.....##.....###
######..............##############............####
#######..###......################.............###
#############.....#########..######............###
#############.....#######.....######...........###
##############...#######........####...##......###
#############.....#####..........####..##.......##
##########.......................####............#
#########........................###.............#
#########...........##............##............##
########............##..........................##
######..........................................##
#####...........................................##
#####..........................#.........####..###
######........................###.......######..##
#######.....................#####.......#####....#
######......................####.........#.......#
######...........................................#
######..........##..................##...........#
#####....#####..##.................###...........#
###.....######...##...#............##...........##
##......#####....########......................###
#.......####......########..##..................##
#........###......########..##...................#
#........###......########.......................#
##.........#.......######......#.................#
##..........#......######.....###...............##
#..........###.....######.....####..............##
#..........##.......######.....###...............#
##.........##........######.....###.....##.......#
###...................#####......###...###......##
####...................#####.....###....#.......##
####....................######.................###
###......................#####...............#####
###................##....###......##........######
##................###.............###......#######
##...............####.............####....########
###..............#####............######..########
#######...#......########.........################
############.....#########....#..#################
##############..###########..#####################
##################################################
用法
类用法示例请参见源代码中提供的示例 main。
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);
}
简单。结果存储在类中,可以通过打印函数中所示的方式访问。
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);
}
运行示例
您可以使用以下命令运行基本示例
cargo run --example base
依赖项
~320–500KB