Browse Source

Some little experiments

Getty Ritter 5 years ago
commit
04f650889d
5 changed files with 213 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 107 0
      Cargo.lock
  3. 17 0
      Cargo.toml
  4. 25 0
      src/circles.rs
  5. 61 0
      src/hexes.rs

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/target
+**/*.rs.bk
+*~

+ 107 - 0
Cargo.lock

@@ -0,0 +1,107 @@
+[[package]]
+name = "axidraw-experiments"
+version = "0.1.0"
+dependencies = [
+ "gunpowder_treason 0.1.0",
+ "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cloudabi"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "either"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "fuchsia-zircon"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "fuchsia-zircon-sys"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "gunpowder_treason"
+version = "0.1.0"
+
+[[package]]
+name = "itertools"
+version = "0.7.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.43"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rand"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
+"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
+"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
+"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
+"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
+"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450"
+"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
+"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
+"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"
+"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 17 - 0
Cargo.toml

@@ -0,0 +1,17 @@
+[package]
+name = "axidraw-experiments"
+version = "0.1.0"
+authors = ["Getty Ritter <gettylefou@gmail.com>"]
+
+[dependencies]
+gunpowder_treason = { path = "../gunpowder_treason" }
+rand = "*"
+itertools = "*"
+
+[[bin]]
+name = "circles"
+path = "src/circles.rs"
+
+[[bin]]
+name = "hexes"
+path = "src/hexes.rs"

+ 25 - 0
src/circles.rs

@@ -0,0 +1,25 @@
+extern crate gunpowder_treason as gt;
+#[macro_use] extern crate itertools;
+extern crate rand;
+
+fn main() {
+    let mut drawing = gt::svg(8.5, 11.0);
+
+    for y in 1..=10 {
+        drawing.add(gt::line(0.75, y as f64)
+                    .to(8.5 - 0.75, y as f64));
+    }
+    for x in 0..=7 {
+        drawing.add(gt::line(0.75 + x as f64, 1.0)
+                    .to(0.75 + x as f64, 10.0));
+    }
+    for (x, y) in iproduct!(0..7, 1..10) {
+        for _ in 0..(rand::random::<u32>() % 4) + 1 {
+            drawing.add(gt::circle(
+                (1.25 + x as f64, 0.5 + y as f64),
+                0.2 * rand::random::<f64>(),
+            ));
+        }
+    }
+    drawing.to_stdout();
+}

+ 61 - 0
src/hexes.rs

@@ -0,0 +1,61 @@
+extern crate gunpowder_treason as gt;
+#[macro_use] extern crate itertools;
+
+use std::f64::consts::PI;
+
+fn main() {
+    let mut drawing = gt::svg(11.0, 14.0);
+    drawing.add(gt::rect((0.0, 0.0), (11.0, 14.0)));
+    const N: f64 = 0.2;
+    const THETA: f64 = PI / 3.0;
+    const COLS: u32 = 16;
+    const ROWS: u32 = 36;
+
+    const XO: f64 = 0.8;
+    const YO: f64 = 0.8;
+
+    for (y, x) in iproduct!(0..ROWS, 0..COLS) {
+        let d = 2.0 * (N + THETA.cos() * N);
+        let a = THETA.cos() * N;
+        let h = THETA.sin() * N;
+        let h2 = THETA.sin() * N * 2.0;
+
+        let by = YO + y as f64 * h2;
+
+        drawing.add(
+            gt::line(XO + d * x as f64, by)
+                .to(XO + d * x as f64 - a, by + h)
+        );
+        drawing.add(
+            gt::line(XO + d * x as f64, by)
+                .to(XO + d * x as f64 + N, by)
+        );
+        drawing.add(
+            gt::line(XO + d * x as f64 + N, by)
+                .to(XO + d * x as f64 + N + a, by + h)
+        );
+        if x < COLS - 1 {
+            drawing.add(
+                gt::line(XO + d * x as f64 + N + a, by + h)
+                    .to(XO + d * x as f64 + N * 2.0 + a, by + h)
+            );
+        }
+
+        drawing.add(
+            gt::line(XO + d * x as f64 - a, by + h)
+                .to(XO + d * x as f64, by + h * 2.0)
+        );
+        if y == ROWS - 1 {
+            drawing.add(
+                gt::line(XO + d * x as f64, by + h * 2.0)
+                    .to(XO + d * x as f64 + N, by + h * 2.0)
+            );
+        }
+        drawing.add(
+            gt::line(XO + d * x as f64 + N + a, by + h)
+                .to(XO + d * x as f64 + N, by + h * 2.0)
+        );
+
+    }
+    drawing.to_stdout();
+}