gdritter repos axidraw-experiments / 95ce928
Merge branch 'master' of rosencrantz:/srv/git/axidraw-experiments Getty Ritter 6 years ago
3 changed file(s) with 67 addition(s) and 2 deletion(s). Collapse all Expand all
2727 [[bin]]
2828 name = "planets"
2929 path = "src/planets.rs"
30
31 [[bin]]
32 name = "space"
33 path = "src/space.rs"
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 }
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 }