gdritter repos axidraw-experiments / dbecf5e
some basic map-drawing Getty Ritter 5 years ago
1 changed file(s) with 74 addition(s) and 0 deletion(s). Collapse all Expand all
1 extern crate gunpowder_treason as gt;
2 #[macro_use] extern crate itertools;
3
4 const MAP: &'static [u8] =
5 b"0000000000000000000001110000111100111100111111001111001001000111010011\
6 1111101110000001001111010011100111111000000100000001111111111111111100\
7 0111111000000000010001111110111011111110000001001110111111100111010011\
8 1011111110011101000100001000000111111111000010000001110100010001110000\
9 0111010011110111111000000100111101110010011101001111000000100111111011\
10 1101110010011100101111011111100010001000000111001001110111110001110110\
11 0010011111110111011001110111110101110111001001111101111101100111011111\
12 000111000000000000000000000000";
13
14 fn main() {
15 let (w, h) = (11.0, 14.0);
16 let mut drawing = gt::svg(w, h);
17 drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
18 const N: f64 = 0.5;
19 let rows: usize = ((w - 1.0) / N).floor() as usize;
20 let cols: usize = ((h - 1.0) / N).floor() as usize;
21 let x_offset = (w - (rows as f64 * N)) / 2.0;
22 let y_offset = (h - (cols as f64 * N)) / 2.0;
23
24 let get_cell = |x: usize, y: usize| {
25 let idx = x + y * rows;
26 MAP[idx]
27 };
28
29 for (x, y) in iproduct!(0..rows-1, 0..cols-1) {
30 let xc = x_offset + x as f64 * N;
31 let yc = y_offset + y as f64 * N;
32 let d = N / 5.0;
33 let cs = N / 10.0;
34 if get_cell(x, y) != get_cell(x + 1, y) {
35 drawing.add(gt::line(xc+N, yc).to(xc+N, yc+N));
36
37 let xt = if get_cell(x, y) == '0' as u8 {
38 xc + N - 0.1
39 } else {
40 xc + N + 0.1
41 };
42 for n in 0..10 {
43 let yt = yc + cs * (n as f64 + 0.5);
44 drawing.add(gt::line(xc+N, yt).to(xt, yt));
45 }
46
47 } else if get_cell(x, y) == '1' as u8 {
48 for n in 1..5 {
49 drawing.add(gt::line(xc+N, yc + d * n as f64));
50 }
51 }
52
53 if get_cell(x, y) != get_cell(x, y+1) {
54 drawing.add(gt::line(xc, yc+N).to(xc+N, yc+N));
55
56 let yt = if get_cell(x, y) == '0' as u8 {
57 yc + N - 0.1
58 } else {
59 yc + N + 0.1
60 };
61 for n in 0..10 {
62 let xt = xc + cs * (n as f64 + 0.5);
63 drawing.add(gt::line(xt, yc+N).to(xt, yt));
64 }
65
66 } else if get_cell(x, y) == '1' as u8 {
67 for n in 1..5 {
68 drawing.add(gt::line(xc + d * n as f64, yc+N));
69 }
70 }
71 }
72
73 drawing.to_stdout();
74 }