11 | 11 |
drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
|
12 | 12 |
|
13 | 13 |
let mut rng = rand::thread_rng();
|
| 14 |
let per_inch = 5.0;
|
14 | 15 |
|
15 | |
let mut points: HashSet<(usize, usize)> = iproduct!(2..40, 2..52).collect();
|
| 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();
|
16 | 20 |
let mut src: Vec<(usize, usize)> = points.clone().into_iter().collect();
|
17 | 21 |
rng.shuffle(&mut src);
|
18 | 22 |
|
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 |
|
23 | |
while let Some((mut x, mut y)) = src.pop() {
|
| 24 |
while let Some((ox, oy)) = src.pop() {
|
| 25 |
let mut x = ox;
|
| 26 |
let mut y = oy;
|
24 | 27 |
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);
|
| 28 |
let mut total_points = 1usize;
|
| 29 |
let mut line = gt::line(x as f64 / per_inch, y as f64 / per_inch);
|
27 | 30 |
'find_next: loop {
|
28 | 31 |
let mut neighbors = vec![
|
29 | 32 |
(x - 1, y),
|
|
38 | 41 |
rng.shuffle(&mut neighbors);
|
39 | 42 |
'check_neighbors: for &(xn, yn) in neighbors.iter() {
|
40 | 43 |
if points.remove(&(xn, yn)) {
|
41 | |
do_add = true;
|
42 | |
line = line.to(xn as f64 / 4.0, yn as f64 / 4.0);
|
| 44 |
total_points += 1;
|
| 45 |
line = line.to(xn as f64 / per_inch, yn as f64 / per_inch);
|
43 | 46 |
x = xn;
|
44 | 47 |
y = yn;
|
45 | 48 |
continue 'find_next;
|
|
47 | 50 |
}
|
48 | 51 |
break 'find_next;
|
49 | 52 |
}
|
50 | |
if do_add {
|
| 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));
|
51 | 56 |
drawing.add(line);
|
52 | 57 |
}
|
53 | 58 |
}
|