gdritter repos axidraw-experiments / 68ebbf5
Some quick mediocre map-ish experiments Getty Ritter 6 years ago
2 changed file(s) with 19 addition(s) and 9 deletion(s). Collapse all Expand all
1414
1515 [[bin]]
1616 name = "hexes"
17 path = "src/hexes.rs"
17 path = "src/hexes.rs"
18
19 [[bin]]
20 name = "grid"
21 path = "src/grid.rs"
1414 fn main() {
1515 let (w, h) = (11.0, 14.0);
1616 let mut drawing = gt::svg(w, h);
17 drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
17 // drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
1818 const N: f64 = 0.5;
1919 let rows: usize = ((w - 1.0) / N).floor() as usize;
2020 let cols: usize = ((h - 1.0) / N).floor() as usize;
2323
2424 let get_cell = |x: usize, y: usize| {
2525 let idx = x + y * rows;
26 MAP.get(idx)
26 if idx < MAP.len() {
27 Some(MAP[idx] as char)
28 } else {
29 None
30 }
2731 };
2832
2933 for (x, y) in iproduct!(0..rows-1, 0..cols-1) {
3337 let cs = N / 10.0;
3438 if get_cell(x, y)
3539 .and_then(|l| get_cell(x + 1, y)
36 .and_then(|r| l != r)).unwrap_or(false) {
40 .map(|r| l != r)).unwrap_or(false) {
3741 drawing.add(gt::line(xc+N, yc).to(xc+N, yc+N));
3842
39 let xt = if get_cell(x, y) == '0' as u8 {
43 let xt = if get_cell(x, y) == Some('0') {
4044 xc + N - 0.1
4145 } else {
4246 xc + N + 0.1
4650 drawing.add(gt::line(xc+N, yt).to(xt, yt));
4751 }
4852
49 } else if get_cell(x, y).unwrap() == '1' as u8 {
53 } else if get_cell(x, y) == Some('1') {
5054 for n in 1..5 {
5155 drawing.add(gt::line(xc+N, yc + d * n as f64));
5256 }
5357 }
5458
55 if get_cell(x, y) != get_cell(x, y+1) {
59 if get_cell(x, y)
60 .and_then(|l| get_cell(x, y+1)
61 .map(|r| l != r)).unwrap_or(false) {
5662 drawing.add(gt::line(xc, yc+N).to(xc+N, yc+N));
5763
58 let yt = if get_cell(x, y) == '0' as u8 {
64 let yt = if get_cell(x, y) == Some('0') {
5965 yc + N - 0.1
6066 } else {
6167 yc + N + 0.1
6571 drawing.add(gt::line(xt, yc+N).to(xt, yt));
6672 }
6773
68 } else if get_cell(x, y).unwrap() == '1' as u8 {
74 } else if get_cell(x, y) == Some('1') {
6975 for n in 1..5 {
7076 drawing.add(gt::line(xc + d * n as f64, yc+N));
7177 }