1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- extern crate gunpowder_treason as gt;
- #[macro_use] extern crate itertools;
- const MAP: &'static [u8] =
- b"0000000000000000000001110000111100111100111111001111001001000111010011\
- 1111101110000001001111010011100111111000000100000001111111111111111100\
- 0111111000000000010001111110111011111110000001001110111111100111010011\
- 1011111110011101000100001000000111111111000010000001110100010001110000\
- 0111010011110111111000000100111101110010011101001111000000100111111011\
- 1101110010011100101111011111100010001000000111001001110111110001110110\
- 0010011111110111011001110111110101110111001001111101111101100111011111\
- 000111000000000000000000000000";
- 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)));
- 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;
- let x_offset = (w - (rows as f64 * N)) / 2.0;
- let y_offset = (h - (cols as f64 * N)) / 2.0;
- let get_cell = |x: usize, y: usize| {
- let idx = x + y * rows;
- MAP[idx]
- };
- for (x, y) in iproduct!(0..rows-1, 0..cols-1) {
- let xc = x_offset + x as f64 * N;
- let yc = y_offset + y as f64 * N;
- let d = N / 5.0;
- let cs = N / 10.0;
- if get_cell(x, y) != get_cell(x + 1, y) {
- drawing.add(gt::line(xc+N, yc).to(xc+N, yc+N));
- let xt = if get_cell(x, y) == '0' as u8 {
- xc + N - 0.1
- } else {
- xc + N + 0.1
- };
- for n in 0..10 {
- let yt = yc + cs * (n as f64 + 0.5);
- drawing.add(gt::line(xc+N, yt).to(xt, yt));
- }
- } else if get_cell(x, y) == '1' as u8 {
- 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) {
- drawing.add(gt::line(xc, yc+N).to(xc+N, yc+N));
- let yt = if get_cell(x, y) == '0' as u8 {
- yc + N - 0.1
- } else {
- yc + N + 0.1
- };
- for n in 0..10 {
- let xt = xc + cs * (n as f64 + 0.5);
- drawing.add(gt::line(xt, yc+N).to(xt, yt));
- }
- } else if get_cell(x, y) == '1' as u8 {
- for n in 1..5 {
- drawing.add(gt::line(xc + d * n as f64, yc+N));
- }
- }
- }
- drawing.to_stdout();
- }
|