14 | 14 |
fn main() {
|
15 | 15 |
let (w, h) = (11.0, 14.0);
|
16 | 16 |
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)));
|
18 | 18 |
const N: f64 = 0.5;
|
19 | 19 |
let rows: usize = ((w - 1.0) / N).floor() as usize;
|
20 | 20 |
let cols: usize = ((h - 1.0) / N).floor() as usize;
|
|
23 | 23 |
|
24 | 24 |
let get_cell = |x: usize, y: usize| {
|
25 | 25 |
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 |
}
|
27 | 31 |
};
|
28 | 32 |
|
29 | 33 |
for (x, y) in iproduct!(0..rows-1, 0..cols-1) {
|
|
33 | 37 |
let cs = N / 10.0;
|
34 | 38 |
if get_cell(x, y)
|
35 | 39 |
.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) {
|
37 | 41 |
drawing.add(gt::line(xc+N, yc).to(xc+N, yc+N));
|
38 | 42 |
|
39 | |
let xt = if get_cell(x, y) == '0' as u8 {
|
| 43 |
let xt = if get_cell(x, y) == Some('0') {
|
40 | 44 |
xc + N - 0.1
|
41 | 45 |
} else {
|
42 | 46 |
xc + N + 0.1
|
|
46 | 50 |
drawing.add(gt::line(xc+N, yt).to(xt, yt));
|
47 | 51 |
}
|
48 | 52 |
|
49 | |
} else if get_cell(x, y).unwrap() == '1' as u8 {
|
| 53 |
} else if get_cell(x, y) == Some('1') {
|
50 | 54 |
for n in 1..5 {
|
51 | 55 |
drawing.add(gt::line(xc+N, yc + d * n as f64));
|
52 | 56 |
}
|
53 | 57 |
}
|
54 | 58 |
|
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) {
|
56 | 62 |
drawing.add(gt::line(xc, yc+N).to(xc+N, yc+N));
|
57 | 63 |
|
58 | |
let yt = if get_cell(x, y) == '0' as u8 {
|
| 64 |
let yt = if get_cell(x, y) == Some('0') {
|
59 | 65 |
yc + N - 0.1
|
60 | 66 |
} else {
|
61 | 67 |
yc + N + 0.1
|
|
65 | 71 |
drawing.add(gt::line(xt, yc+N).to(xt, yt));
|
66 | 72 |
}
|
67 | 73 |
|
68 | |
} else if get_cell(x, y).unwrap() == '1' as u8 {
|
| 74 |
} else if get_cell(x, y) == Some('1') {
|
69 | 75 |
for n in 1..5 {
|
70 | 76 |
drawing.add(gt::line(xc + d * n as f64, yc+N));
|
71 | 77 |
}
|