demo-tile.rs
1.9 kB · rust · 57 lines
1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board, Grid};3use mrlymath::two;4use mrlymath::two::census;56const CODE: u128 = 495;7const NUMBER: usize = 3;8const BASE: usize = 3;9const LEVEL: usize = 2;10const COPIES: usize = 5;11const TILE: usize = 9;12const SIDE: usize = 45;1314fn main() -> Result<()> {15 let mut board = Board::square();16 let frame = board.frame(0.08);17 let tile = two::create(CODE, NUMBER, LEVEL, 0, BASE)?;18 assert_eq!((tile.width(), census::fills(&tile)), (TILE, 64));19 assert_eq!(census::perimeter(&tile), 80);20 let sheet = tile.tile(COPIES, COPIES);21 assert_eq!((sheet.width(), census::fills(&sheet)), (SIDE, 1600));22 assert_eq!(census::perimeter(&sheet), 1280);23 let buried = 25 * 80 - census::perimeter(&sheet);24 assert_eq!(buried, 720);25 let types = sheet.types();26 let on = |row: usize, col: usize| types.get(&[row, col]) != 0;27 let grid = Grid::new(frame, SIDE, SIDE, 0.0);28 for row in 0..SIDE {29 for col in 0..SIDE {30 if on(row, col) {31 grid.fill(&mut board, col, row, ink::blue());32 }33 }34 }35 let thick = frame.cell(SIDE) * 0.26;36 let mut seams = 0usize;37 for row in 0..SIDE {38 for col in 0..SIDE {39 if !on(row, col) {40 continue;41 }42 let (x, y, w, h) = grid.cell(col, row);43 if col % TILE == TILE - 1 && col + 1 < SIDE && on(row, col + 1) {44 board.segment((x + w, y), (x + w, y + h), thick, ink::orange());45 seams += 1;46 }47 if row % TILE == TILE - 1 && row + 1 < SIDE && on(row + 1, col) {48 board.segment((x, y + h), (x + w, y + h), thick, ink::orange());49 seams += 1;50 }51 }52 }53 assert_eq!(seams * 2, buried as usize);54 assert_eq!(seams, 360);55 save("demo-tile", &board)?;56 Ok(())57}