gdritter repos axidraw-experiments / b7d2ac9
Add Sunburst and Planets programs Getty Ritter 5 years ago
4 changed file(s) with 115 addition(s) and 41 deletion(s). Collapse all Expand all
1818
1919 [[bin]]
2020 name = "grid"
21 path = "src/grid.rs"
21 path = "src/grid.rs"
22
23 [[bin]]
24 name = "sunburst"
25 path = "src/sunburst.rs"
26
27 [[bin]]
28 name = "planets"
29 path = "src/planets.rs"
11 extern crate gunpowder_treason as gt;
2 #[macro_use] extern crate itertools;
2 extern crate itertools;
33
44 use std::f64::consts::PI;
55
66 fn main() {
7 let mut drawing = gt::svg(11.0, 14.0);
8 drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
7 let cent = 0.393701f64;
8 let mut drawing = gt::svg(23.0 * cent, 30.0 * cent);
9 drawing.add(gt::rect((0.0, 0.0), (23.0 * cent, 30.0 * cent)));
910 const N: f64 = 0.2;
1011 const THETA: f64 = PI / 3.0;
11 const COLS: u32 = 16;
12 const ROWS: u32 = 36;
12 const COLS: u32 = 13;
13 const ROWS: u32 = 30;
1314
1415 const XO: f64 = 0.8;
1516 const YO: f64 = 0.8;
1617
17 for (y, x) in iproduct!(0..ROWS, 0..COLS) {
18 let d = 2.0 * (N + THETA.cos() * N);
19 let a = THETA.cos() * N;
20 let h = THETA.sin() * N;
21 let h2 = THETA.sin() * N * 2.0;
18 let a = THETA.cos() * N;
19 let h = THETA.sin() * N;
20 let h2 = THETA.sin() * N * 2.0;
21 let d = 2.0 * (N + THETA.cos() * N);
22 for y in 0..ROWS {
23 let by = YO + y as f64 * h2;
24 for x in 0..COLS {
2225
23 let by = YO + y as f64 * h2;
26 drawing.add(
27 gt::line(XO + d * x as f64 - a, by + h)
28 .to(XO + d * x as f64, by)
29 );
30 drawing.add(
31 gt::line(XO + d * x as f64, by)
32 .to(XO + d * x as f64 + N, by)
33 );
34 drawing.add(
35 gt::line(XO + d * x as f64 + N, by)
36 .to(XO + d * x as f64 + N + a, by + h)
37 );
38 if x < COLS - 1 {
39 drawing.add(
40 gt::line(XO + d * x as f64 + N + a, by + h)
41 .to(XO + d * x as f64 + N * 2.0 + a, by + h)
42 );
43 }
44 }
2445
25 drawing.add(
26 gt::line(XO + d * x as f64, by)
27 .to(XO + d * x as f64 - a, by + h)
28 );
29 drawing.add(
30 gt::line(XO + d * x as f64, by)
31 .to(XO + d * x as f64 + N, by)
32 );
33 drawing.add(
34 gt::line(XO + d * x as f64 + N, by)
35 .to(XO + d * x as f64 + N + a, by + h)
36 );
37 if x < COLS - 1 {
46 for x in 0..COLS {
47
48 drawing.add(
49 gt::line(XO + d * x as f64, by + h * 2.0)
50 .to(XO + d * x as f64 - a, by + h)
51 );
52 if y == ROWS - 1 {
53 drawing.add(
54 gt::line(XO + d * x as f64, by + h * 2.0)
55 .to(XO + d * x as f64 + N, by + h * 2.0)
56 );
57 }
3858 drawing.add(
3959 gt::line(XO + d * x as f64 + N + a, by + h)
40 .to(XO + d * x as f64 + N * 2.0 + a, by + h)
41 );
42 }
43
44 drawing.add(
45 gt::line(XO + d * x as f64 - a, by + h)
46 .to(XO + d * x as f64, by + h * 2.0)
47 );
48 if y == ROWS - 1 {
49 drawing.add(
50 gt::line(XO + d * x as f64, by + h * 2.0)
5160 .to(XO + d * x as f64 + N, by + h * 2.0)
5261 );
5362 }
54 drawing.add(
55 gt::line(XO + d * x as f64 + N + a, by + h)
56 .to(XO + d * x as f64 + N, by + h * 2.0)
57 );
58
5963 }
6064 drawing.to_stdout();
6165 }
1 extern crate gunpowder_treason as gt;
2 extern crate rand;
3
4 use rand::random;
5
6 fn main() {
7 let cent = 0.393701;
8 let mut drawing = gt::svg(9.0, 12.0);
9
10 let xs: Vec<Vec<f64>> = (1..9).map(|_: u32| {
11 (0..(random::<u32>() % 8) + 4).map(|_: u32| {
12 (random::<f64>() * 0.3 + 0.3) * 0.2
13 }).collect()
14 }).collect();
15
16 for (x, rs) in xs.iter().enumerate() {
17 let max = rs.len();
18 let tot = (max - 1) as f64;
19 let dy = 10.0 / tot;
20 let mut ry = 1.0;
21 let r2 = rs.clone();
22 for (y, c) in rs.iter().enumerate() {
23 let rx = 1.0 + x as f64;
24 eprintln!("{}, {}, {}, {}", x, y, c, ry);
25 drawing.add(gt::circle(
26 (rx, 1.0 + dy * y as f64),
27 *c,
28 ));
29 if y != max - 1 {
30 let cn = r2[y + 1];
31 drawing.add(gt::line(rx, ry + c).to(rx, ry + dy - cn));
32 }
33 ry += dy;
34 }
35 }
36
37 drawing.to_stdout();
38 }
1 extern crate gunpowder_treason as gt;
2 extern crate rand;
3
4 fn main() {
5 let (w, h) = (8.5, 11.0);
6 let mut drawing = gt::svg(w, h);
7
8 let rs = (0u64..100)
9 .scan((0u64, 5.5f64), |(_, s), x: u64| {
10 Some((x, *s + (rand::random::<f64>() * 0.5) - 0.25))
11 });
12
13 for (x, r) in rs {
14 let xn = 0.8 + (x as f64 * (8.5 - 1.6)) / 100.0;
15 drawing.add(
16 gt::line(xn, 0.8).to(xn, r - 0.8)
17 );
18 drawing.add(
19 gt::line(xn, 10.2).to(xn, r + 0.8)
20 );
21 }
22
23 drawing.to_stdout();
24 }