14126
|
1 |
extern crate integral_geometry;
|
|
2 |
extern crate land2d;
|
|
3 |
extern crate landgen;
|
|
4 |
extern crate lfprng;
|
|
5 |
extern crate png;
|
|
6 |
extern crate structopt;
|
|
7 |
|
|
8 |
use png::HasParameters;
|
|
9 |
use std::fs::File;
|
|
10 |
use std::io::BufWriter;
|
|
11 |
use std::path::Path;
|
|
12 |
use structopt::StructOpt;
|
|
13 |
|
|
14 |
use integral_geometry::{Point, Rect, Size};
|
|
15 |
use landgen::outline_template::OutlineTemplate;
|
|
16 |
use landgen::template_based::TemplatedLandGenerator;
|
|
17 |
use landgen::LandGenerationParameters;
|
|
18 |
use landgen::LandGenerator;
|
|
19 |
use lfprng::LaggedFibonacciPRNG;
|
|
20 |
|
|
21 |
#[derive(StructOpt, Debug)]
|
|
22 |
#[structopt(name = "basic")]
|
|
23 |
struct Opt {
|
|
24 |
#[structopt(short = "s", long = "seed", default_value = "TEST_SEED")]
|
|
25 |
seed: String,
|
|
26 |
#[structopt(short = "d", long = "dump-before-distort")]
|
|
27 |
dump_before_distort: bool,
|
|
28 |
#[structopt(short = "b", long = "dump-before-bezierize")]
|
|
29 |
dump_before_bezierize: bool,
|
14130
|
30 |
#[structopt(short = "f", long = "distance-divisor", default_value = "100")]
|
|
31 |
distance_divisor: u32,
|
14126
|
32 |
}
|
|
33 |
|
|
34 |
fn template() -> OutlineTemplate {
|
|
35 |
let mut template = OutlineTemplate::new(Size::new(4096, 2048));
|
|
36 |
template.islands = vec![vec![
|
|
37 |
Rect::new(100, 2050, 1, 1),
|
|
38 |
Rect::new(100, 500, 400, 1200),
|
|
39 |
Rect::new(3600, 500, 400, 1200),
|
|
40 |
Rect::new(3900, 2050, 1, 1),
|
|
41 |
]];
|
|
42 |
template.fill_points = vec![Point::new(2047, 2047)];
|
|
43 |
|
|
44 |
template
|
|
45 |
}
|
|
46 |
|
|
47 |
fn dump(
|
|
48 |
seed: &[u8],
|
14130
|
49 |
distance_divisor: u32,
|
14126
|
50 |
skip_distort: bool,
|
|
51 |
skip_bezier: bool,
|
|
52 |
file_name: &Path,
|
|
53 |
) -> std::io::Result<()> {
|
14130
|
54 |
let params = LandGenerationParameters::new(0 as u8, 255, distance_divisor, skip_distort, skip_bezier);
|
14126
|
55 |
let landgen = TemplatedLandGenerator::new(template());
|
|
56 |
let mut prng = LaggedFibonacciPRNG::new(seed);
|
|
57 |
let land = landgen.generate_land(¶ms, &mut prng);
|
|
58 |
|
|
59 |
let file = File::create(file_name)?;
|
|
60 |
let ref mut w = BufWriter::new(file);
|
|
61 |
|
|
62 |
let mut encoder = png::Encoder::new(w, land.width() as u32, land.height() as u32); // Width is 2 pixels and height is 1.
|
|
63 |
encoder
|
|
64 |
.set(png::ColorType::Grayscale)
|
|
65 |
.set(png::BitDepth::Eight);
|
|
66 |
let mut writer = encoder.write_header()?;
|
|
67 |
|
|
68 |
writer.write_image_data(land.raw_pixels()).unwrap();
|
|
69 |
|
|
70 |
Ok(())
|
|
71 |
}
|
|
72 |
|
|
73 |
fn main() {
|
|
74 |
let opt = Opt::from_args();
|
|
75 |
println!("{:?}", opt);
|
|
76 |
|
|
77 |
if opt.dump_before_distort {
|
|
78 |
dump(
|
|
79 |
opt.seed.as_str().as_bytes(),
|
14130
|
80 |
opt.distance_divisor,
|
14126
|
81 |
true,
|
|
82 |
true,
|
|
83 |
Path::new("out.before_distort.png"),
|
|
84 |
)
|
|
85 |
.unwrap();
|
|
86 |
}
|
|
87 |
if opt.dump_before_bezierize {
|
|
88 |
dump(
|
|
89 |
opt.seed.as_str().as_bytes(),
|
14130
|
90 |
opt.distance_divisor,
|
14126
|
91 |
false,
|
|
92 |
true,
|
|
93 |
Path::new("out.before_bezier.png"),
|
|
94 |
)
|
|
95 |
.unwrap();
|
|
96 |
}
|
|
97 |
dump(
|
|
98 |
opt.seed.as_str().as_bytes(),
|
14130
|
99 |
opt.distance_divisor,
|
14126
|
100 |
false,
|
|
101 |
true,
|
|
102 |
Path::new("out.full.png"),
|
|
103 |
)
|
|
104 |
.unwrap();
|
|
105 |
}
|