Skip to main content

function/
function.rs

1extern crate marching_squares;
2use marching_squares::{Field, Point};
3
4fn main() {
5    // Build the field
6
7    let width = 1600_usize;
8    let height = 1600_usize;
9    let n_steps = 10_usize;
10
11    let mut min_val = 0;
12    let mut max_val = 0;
13
14    let z_values = (0..height).map(|y| {
15        (0..width).map(|x| {
16            let x = (x as f64 - width as f64 / 2.0) / 150.0;
17            let y = (y as f64 - height as f64 / 2.0) / 150.0;
18            let val = ((1.3 * x).sin() * (0.9 * y).cos() + (0.8 * x).cos() * (1.9 * y).sin() + (y * 0.2 * x).cos()) as i16;
19            min_val = min_val.min(val);
20            max_val = max_val.max(val);
21            val
22        }).collect()
23    }).collect::<Vec<Vec<i16>>>();
24
25    let field = Field {
26        dimensions: (width, height),
27        top_left: Point { x: 0.0, y: 0.0 },
28        pixel_size: (1.0, 1.0),
29        values: &z_values,
30    };
31
32    let step_size = (max_val - min_val) as f32 / n_steps as f32;
33
34    for step in 0..n_steps {
35        let isoline_height = min_val as f32 + (step_size * step as f32);
36        println!("{:#?}", field.get_contours(isoline_height as i16));
37    }
38}