|
@@ -14,7 +14,7 @@ const MAP: &'static [u8] =
|
|
|
fn main() {
|
|
|
let (w, h) = (11.0, 14.0);
|
|
|
let mut drawing = gt::svg(w, h);
|
|
|
- drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
|
|
|
+ // drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
|
|
|
const N: f64 = 0.5;
|
|
|
let rows: usize = ((w - 1.0) / N).floor() as usize;
|
|
|
let cols: usize = ((h - 1.0) / N).floor() as usize;
|
|
@@ -23,7 +23,11 @@ fn main() {
|
|
|
|
|
|
let get_cell = |x: usize, y: usize| {
|
|
|
let idx = x + y * rows;
|
|
|
- MAP.get(idx)
|
|
|
+ if idx < MAP.len() {
|
|
|
+ Some(MAP[idx] as char)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
for (x, y) in iproduct!(0..rows-1, 0..cols-1) {
|
|
@@ -33,10 +37,10 @@ fn main() {
|
|
|
let cs = N / 10.0;
|
|
|
if get_cell(x, y)
|
|
|
.and_then(|l| get_cell(x + 1, y)
|
|
|
- .and_then(|r| l != r)).unwrap_or(false) {
|
|
|
+ .map(|r| l != r)).unwrap_or(false) {
|
|
|
drawing.add(gt::line(xc+N, yc).to(xc+N, yc+N));
|
|
|
|
|
|
- let xt = if get_cell(x, y) == '0' as u8 {
|
|
|
+ let xt = if get_cell(x, y) == Some('0') {
|
|
|
xc + N - 0.1
|
|
|
} else {
|
|
|
xc + N + 0.1
|
|
@@ -46,16 +50,18 @@ fn main() {
|
|
|
drawing.add(gt::line(xc+N, yt).to(xt, yt));
|
|
|
}
|
|
|
|
|
|
- } else if get_cell(x, y).unwrap() == '1' as u8 {
|
|
|
+ } else if get_cell(x, y) == Some('1') {
|
|
|
for n in 1..5 {
|
|
|
drawing.add(gt::line(xc+N, yc + d * n as f64));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if get_cell(x, y) != get_cell(x, y+1) {
|
|
|
+ if get_cell(x, y)
|
|
|
+ .and_then(|l| get_cell(x, y+1)
|
|
|
+ .map(|r| l != r)).unwrap_or(false) {
|
|
|
drawing.add(gt::line(xc, yc+N).to(xc+N, yc+N));
|
|
|
|
|
|
- let yt = if get_cell(x, y) == '0' as u8 {
|
|
|
+ let yt = if get_cell(x, y) == Some('0') {
|
|
|
yc + N - 0.1
|
|
|
} else {
|
|
|
yc + N + 0.1
|
|
@@ -65,7 +71,7 @@ fn main() {
|
|
|
drawing.add(gt::line(xt, yc+N).to(xt, yt));
|
|
|
}
|
|
|
|
|
|
- } else if get_cell(x, y).unwrap() == '1' as u8 {
|
|
|
+ } else if get_cell(x, y) == Some('1') {
|
|
|
for n in 1..5 {
|
|
|
drawing.add(gt::line(xc + d * n as f64, yc+N));
|
|
|
}
|