Browse Source

Some back-compat for old Rust and some work on the space colonization-ish lines piece

Getty Ritter 5 years ago
parent
commit
8511a2cdde
2 changed files with 17 additions and 12 deletions
  1. 2 2
      src/circles.rs
  2. 15 10
      src/space.rs

+ 2 - 2
src/circles.rs

@@ -5,11 +5,11 @@ extern crate rand;
 fn main() {
     let mut drawing = gt::svg(8.5, 11.0);
 
-    for y in 1..=10 {
+    for y in 1..11 {
         drawing.add(gt::line(0.75, y as f64)
                     .to(8.5 - 0.75, y as f64));
     }
-    for x in 0..=7 {
+    for x in 0..8 {
         drawing.add(gt::line(0.75 + x as f64, 1.0)
                     .to(0.75 + x as f64, 10.0));
     }

+ 15 - 10
src/space.rs

@@ -11,19 +11,22 @@ fn main() {
     drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
 
     let mut rng = rand::thread_rng();
+    let per_inch = 5.0;
 
-    let mut points: HashSet<(usize, usize)> = iproduct!(2..40, 2..52).collect();
+    let mut points: HashSet<(usize, usize)> = iproduct!(
+        per_inch as usize .. per_inch as usize * 10,
+        per_inch as usize .. per_inch as usize * 13
+    ).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() {
+    while let Some((ox, oy)) = src.pop() {
+        let mut x = ox;
+        let mut y = oy;
         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);
+        let mut total_points = 1usize;
+        let mut line = gt::line(x as f64 / per_inch, y as f64 / per_inch);
         'find_next: loop {
             let mut neighbors = vec![
                 (x - 1, y),
@@ -38,8 +41,8 @@ fn main() {
             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);
+                    total_points += 1;
+                    line = line.to(xn as f64 / per_inch, yn as f64 / per_inch);
                     x = xn;
                     y = yn;
                     continue 'find_next;
@@ -47,7 +50,9 @@ fn main() {
             }
             break 'find_next;
         }
-        if do_add {
+        if total_points > 3 {
+            drawing.add(gt::circle((ox as f64 / per_inch, oy as f64 / per_inch), 0.02));
+            drawing.add(gt::circle((x as f64 / per_inch, y as f64 / per_inch), 0.02));
             drawing.add(line);
         }
     }