planets.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. extern crate gunpowder_treason as gt;
  2. extern crate rand;
  3. use rand::random;
  4. fn main() {
  5. // let cent = 0.393701;
  6. let mut drawing = gt::svg(9.0, 12.0);
  7. let xs: Vec<Vec<f64>> = (1..9).map(|_: u32| {
  8. (0..(random::<u32>() % 8) + 4).map(|_: u32| {
  9. (random::<f64>() * 0.3 + 0.3) * 0.2
  10. }).collect()
  11. }).collect();
  12. for (x, rs) in xs.iter().enumerate() {
  13. let max = rs.len();
  14. let tot = (max - 1) as f64;
  15. let dy = 10.0 / tot;
  16. let mut ry = 1.0;
  17. let r2 = rs.clone();
  18. for (y, c) in rs.iter().enumerate() {
  19. let rx = 1.0 + x as f64;
  20. eprintln!("{}, {}, {}, {}", x, y, c, ry);
  21. drawing.add(gt::circle(
  22. (rx, 1.0 + dy * y as f64),
  23. *c,
  24. ));
  25. if y != max - 1 {
  26. let cn = r2[y + 1];
  27. drawing.add(gt::line(rx, ry + c).to(rx, ry + dy - cn));
  28. }
  29. ry += dy;
  30. }
  31. }
  32. if let Err(e) = drawing.output("planets") {
  33. eprintln!("{}", e);
  34. };
  35. }