wiki-moire.rs
1.7 kB · rust · 57 lines
1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board};3use mrlynum::factor::gcd;45const SCALES: (usize, usize) = (5, 7);67fn marks(n: usize) -> Vec<f64> {8 (0..=n).map(|k| k as f64 / n as f64).collect()9}1011fn main() -> Result<()> {12 let (small, large) = SCALES;13 let common = gcd(small, large);14 let shared = marks(common);15 let thin = marks(small);16 let thick = marks(large);17 let mut crossings: Vec<(f64, f64)> = Vec::new();18 for &x in &thin {19 for &y in &thick {20 crossings.push((x, y));21 if !thin.contains(&y) || !thick.contains(&x) {22 crossings.push((y, x));23 }24 }25 }26 assert_eq!(common, 1);27 assert_eq!(shared.len(), 2);28 assert_eq!(crossings.len(), 92);2930 let mut board = Board::square();31 let frame = board.frame(0.10);32 let at = |u: f64, v: f64| (frame.x + u * frame.w, frame.y + v * frame.h);33 for &u in &thin {34 let (x, top) = at(u, 0.0);35 let (left, y) = at(0.0, u);36 board.segment((x, top), (x, top + frame.h), 5.0, ink::blue());37 board.segment((left, y), (left + frame.w, y), 5.0, ink::blue());38 }39 for &u in &thick {40 let (x, top) = at(u, 0.0);41 let (left, y) = at(0.0, u);42 board.segment((x, top), (x, top + frame.h), 5.0, ink::orange());43 board.segment((left, y), (left + frame.w, y), 5.0, ink::orange());44 }45 for &(u, v) in &crossings {46 let (x, y) = at(u, v);47 board.disc(x, y, frame.w * 0.010, ink::fade(ink::dim(), 0.9));48 }49 for &u in &shared {50 for &v in &shared {51 let (x, y) = at(u, v);52 board.disc(x, y, frame.w * 0.035, ink::yellow());53 }54 }55 save("wiki-moire", &board)?;56 Ok(())57}