gdritter repos axidraw-experiments / 8511a2c
Some back-compat for old Rust and some work on the space colonization-ish lines piece Getty Ritter 5 years ago
2 changed file(s) with 17 addition(s) and 12 deletion(s). Collapse all Expand all
55 fn main() {
66 let mut drawing = gt::svg(8.5, 11.0);
77
8 for y in 1..=10 {
8 for y in 1..11 {
99 drawing.add(gt::line(0.75, y as f64)
1010 .to(8.5 - 0.75, y as f64));
1111 }
12 for x in 0..=7 {
12 for x in 0..8 {
1313 drawing.add(gt::line(0.75 + x as f64, 1.0)
1414 .to(0.75 + x as f64, 10.0));
1515 }
1111 drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
1212
1313 let mut rng = rand::thread_rng();
14 let per_inch = 5.0;
1415
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();
1620 let mut src: Vec<(usize, usize)> = points.clone().into_iter().collect();
1721 rng.shuffle(&mut src);
1822
19 // for &(x, y) in points.iter() {
20 // drawing.add(gt::line(x as f64 / 2.0, y as f64 / 2.0));
21 // }
2223
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;
2427 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);
2730 'find_next: loop {
2831 let mut neighbors = vec![
2932 (x - 1, y),
3841 rng.shuffle(&mut neighbors);
3942 'check_neighbors: for &(xn, yn) in neighbors.iter() {
4043 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);
4346 x = xn;
4447 y = yn;
4548 continue 'find_next;
4750 }
4851 break 'find_next;
4952 }
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));
5156 drawing.add(line);
5257 }
5358 }