| 1 |
extern crate gunpowder_treason as gt;
|
| 2 |
#[macro_use] extern crate itertools;
|
| 3 |
extern crate rand;
|
| 4 |
|
| 5 |
use std::collections::HashSet;
|
| 6 |
use rand::Rng;
|
| 7 |
|
| 8 |
fn main() {
|
| 9 |
let (w, h) = (11.0, 14.0);
|
| 10 |
let mut drawing = gt::svg(w, h);
|
| 11 |
drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
|
| 12 |
|
| 13 |
let mut rng = rand::thread_rng();
|
| 14 |
|
| 15 |
let mut points: HashSet<(usize, usize)> = iproduct!(2..40, 2..52).collect();
|
| 16 |
let mut src: Vec<(usize, usize)> = points.clone().into_iter().collect();
|
| 17 |
rng.shuffle(&mut src);
|
| 18 |
|
| 19 |
// for &(x, y) in points.iter() {
|
| 20 |
// drawing.add(gt::line(x as f64 / 2.0, y as f64 / 2.0));
|
| 21 |
// }
|
| 22 |
|
| 23 |
while let Some((mut x, mut y)) = src.pop() {
|
| 24 |
if !points.remove(&(x, y)) { continue; }
|
| 25 |
let mut do_add = false;
|
| 26 |
let mut line = gt::line(x as f64 / 4.0, y as f64 / 4.0);
|
| 27 |
'find_next: loop {
|
| 28 |
let mut neighbors = vec![
|
| 29 |
(x - 1, y),
|
| 30 |
(x + 1, y),
|
| 31 |
(x, y - 1),
|
| 32 |
(x, y + 1),
|
| 33 |
(x, y - 1),
|
| 34 |
(x, y + 1),
|
| 35 |
(x, y - 1),
|
| 36 |
(x, y + 1),
|
| 37 |
];
|
| 38 |
rng.shuffle(&mut neighbors);
|
| 39 |
'check_neighbors: for &(xn, yn) in neighbors.iter() {
|
| 40 |
if points.remove(&(xn, yn)) {
|
| 41 |
do_add = true;
|
| 42 |
line = line.to(xn as f64 / 4.0, yn as f64 / 4.0);
|
| 43 |
x = xn;
|
| 44 |
y = yn;
|
| 45 |
continue 'find_next;
|
| 46 |
}
|
| 47 |
}
|
| 48 |
break 'find_next;
|
| 49 |
}
|
| 50 |
if do_add {
|
| 51 |
drawing.add(line);
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|
| 55 |
drawing.to_stdout();
|
| 56 |
}
|