site-wiki.rs

1.6 kB · rust · 52 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board, Frame, Grid};3use mrlymath::two::designs;45const CODES: [u128; 7] = [7, 14, 3, 5, 9, 6, 15];6const SIDE: usize = 9;7const GUTTER: f64 = 130.0;8const EDGE: f64 = 3.0;910fn place(index: usize) -> (usize, usize) {11    match index {12        0 => (0, 1),13        n if n < 4 => (1, n - 1),14        n => (2, n - 4),15    }16}1718fn main() -> Result<()> {19    let mut board = Board::square();20    let area = board.frame(0.08);21    let tile = (area.w - 2.0 * GUTTER) / 3.0;22    let step = tile + GUTTER;23    let corner = |index: usize| {24        let (row, col) = place(index);25        (area.x + col as f64 * step, area.y + row as f64 * step)26    };27    let foot = |index: usize| {28        let (x, y) = corner(index);29        (x + tile / 2.0, y + tile)30    };31    let head = |index: usize| {32        let (x, y) = corner(index);33        (x + tile / 2.0, y)34    };35    for child in 1..CODES.len() {36        let parent = if child < 4 { 0 } else { child - 3 };37        board.segment(foot(parent), head(child), EDGE, ink::line());38    }39    let mut cells = 0u64;40    for (index, code) in CODES.iter().enumerate() {41        let design = designs::create(*code, 3, 2, 0, 2)?;42        assert_eq!(design.width(), SIDE);43        let tone = if index == 0 { ink::yellow() } else { ink::blue() };44        let (x, y) = corner(index);45        Grid::new(Frame::new(x, y, tile, tile), SIDE, SIDE, 0.0)46            .paint(&mut board, &design, |kind| (kind != 0).then_some(tone));47        cells += design.types().sum();48    }49    assert_eq!(cells, 283);50    save("site-wiki", &board)?;51    Ok(())52}