hexes.rs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. extern crate gunpowder_treason as gt;
  2. extern crate itertools;
  3. use std::f64::consts::PI;
  4. fn main() {
  5. let cent = 0.393701f64;
  6. let mut drawing = gt::svg(23.0 * cent, 30.0 * cent);
  7. drawing.add(gt::rect((0.0, 0.0), (23.0 * cent, 30.0 * cent)));
  8. const N: f64 = 0.2;
  9. const THETA: f64 = PI / 3.0;
  10. const COLS: u32 = 13;
  11. const ROWS: u32 = 30;
  12. const XO: f64 = 0.8;
  13. const YO: f64 = 0.8;
  14. let a = THETA.cos() * N;
  15. let h = THETA.sin() * N;
  16. let h2 = THETA.sin() * N * 2.0;
  17. let d = 2.0 * (N + THETA.cos() * N);
  18. for y in 0..ROWS {
  19. let by = YO + y as f64 * h2;
  20. for x in 0..COLS {
  21. drawing.add(
  22. gt::line(XO + d * x as f64 - a, by + h)
  23. .to(XO + d * x as f64, by)
  24. );
  25. drawing.add(
  26. gt::line(XO + d * x as f64, by)
  27. .to(XO + d * x as f64 + N, by)
  28. );
  29. drawing.add(
  30. gt::line(XO + d * x as f64 + N, by)
  31. .to(XO + d * x as f64 + N + a, by + h)
  32. );
  33. if x < COLS - 1 {
  34. drawing.add(
  35. gt::line(XO + d * x as f64 + N + a, by + h)
  36. .to(XO + d * x as f64 + N * 2.0 + a, by + h)
  37. );
  38. }
  39. }
  40. for x in 0..COLS {
  41. drawing.add(
  42. gt::line(XO + d * x as f64, by + h * 2.0)
  43. .to(XO + d * x as f64 - a, by + h)
  44. );
  45. if y == ROWS - 1 {
  46. drawing.add(
  47. gt::line(XO + d * x as f64, by + h * 2.0)
  48. .to(XO + d * x as f64 + N, by + h * 2.0)
  49. );
  50. }
  51. drawing.add(
  52. gt::line(XO + d * x as f64 + N + a, by + h)
  53. .to(XO + d * x as f64 + N, by + h * 2.0)
  54. );
  55. }
  56. }
  57. if let Err(e) = drawing.output("hexes") {
  58. eprintln!("{}", e);
  59. }
  60. }