extern crate gunpowder_treason as gt; #[macro_use] extern crate itertools; extern crate rand; use std::collections::HashSet; use rand::Rng; 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))); let mut rng = rand::thread_rng(); let mut points: HashSet<(usize, usize)> = iproduct!(2..40, 2..52).collect(); let mut src: Vec<(usize, usize)> = points.clone().into_iter().collect(); rng.shuffle(&mut src); // for &(x, y) in points.iter() { // drawing.add(gt::line(x as f64 / 2.0, y as f64 / 2.0)); // } while let Some((mut x, mut y)) = src.pop() { if !points.remove(&(x, y)) { continue; } let mut do_add = false; let mut line = gt::line(x as f64 / 4.0, y as f64 / 4.0); 'find_next: loop { let mut neighbors = vec![ (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1), (x, y - 1), (x, y + 1), (x, y - 1), (x, y + 1), ]; rng.shuffle(&mut neighbors); 'check_neighbors: for &(xn, yn) in neighbors.iter() { if points.remove(&(xn, yn)) { do_add = true; line = line.to(xn as f64 / 4.0, yn as f64 / 4.0); x = xn; y = yn; continue 'find_next; } } break 'find_next; } if do_add { drawing.add(line); } } drawing.to_stdout(); }