| 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 |
let per_inch = 5.0;
|
| 15 |
|
| 16 |
let mut points: HashSet<(usize, usize)> = iproduct!(
|
| 17 |
per_inch as usize .. per_inch as usize * 10,
|
| 18 |
per_inch as usize .. per_inch as usize * 13
|
| 19 |
).collect();
|
| 20 |
let mut src: Vec<(usize, usize)> = points.clone().into_iter().collect();
|
| 21 |
rng.shuffle(&mut src);
|
| 22 |
|
| 23 |
|
| 24 |
while let Some((ox, oy)) = src.pop() {
|
| 25 |
let mut x = ox;
|
| 26 |
let mut y = oy;
|
| 27 |
if !points.remove(&(x, y)) { continue; }
|
| 28 |
let mut total_points = 1usize;
|
| 29 |
let mut line = gt::line(x as f64 / per_inch, y as f64 / per_inch);
|
| 30 |
'find_next: loop {
|
| 31 |
let mut neighbors = vec![
|
| 32 |
(x - 1, y),
|
| 33 |
(x + 1, y),
|
| 34 |
(x, y - 1),
|
| 35 |
(x, y + 1),
|
| 36 |
(x, y - 1),
|
| 37 |
(x, y + 1),
|
| 38 |
(x, y - 1),
|
| 39 |
(x, y + 1),
|
| 40 |
];
|
| 41 |
rng.shuffle(&mut neighbors);
|
| 42 |
'check_neighbors: for &(xn, yn) in neighbors.iter() {
|
| 43 |
if points.remove(&(xn, yn)) {
|
| 44 |
total_points += 1;
|
| 45 |
line = line.to(xn as f64 / per_inch, yn as f64 / per_inch);
|
| 46 |
x = xn;
|
| 47 |
y = yn;
|
| 48 |
continue 'find_next;
|
| 49 |
}
|
| 50 |
}
|
| 51 |
break 'find_next;
|
| 52 |
}
|
| 53 |
if total_points > 3 {
|
| 54 |
drawing.add(gt::circle((ox as f64 / per_inch, oy as f64 / per_inch), 0.02));
|
| 55 |
drawing.add(gt::circle((x as f64 / per_inch, y as f64 / per_inch), 0.02));
|
| 56 |
drawing.add(line);
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
drawing.to_stdout();
|
| 61 |
}
|