site-math.rs
1.3 kB · rust · 42 lines
1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board, Frame, Grid};3use mrlymath::two::designs;45const CODE: u128 = 7;6const BITS: usize = 8;7const SIDE: usize = 27;8const WIDE: f64 = 594.0;9const TOP: f64 = 140.0;10const THIN: f64 = 3.0;1112fn main() -> Result<()> {13 let mut board = Board::square();14 let left = (board.width as f64 - WIDE) / 2.0;15 let pitch = WIDE / BITS as f64;16 let row = Grid::new(Frame::new(left, TOP, WIDE, pitch), BITS, 1, 0.14);17 let mut lit = 0u32;18 for bit in 0..BITS {19 let (x, y, w, h) = row.cell(bit, 0);20 if (CODE & (1 << bit)) != 0 {21 board.rect(x, y, w, h, ink::fg());22 lit += 1;23 } else {24 board.rect(x, y, w, h, ink::line());25 board.rect(26 x + THIN,27 y + THIN,28 w - 2.0 * THIN,29 h - 2.0 * THIN,30 ink::ground(),31 );32 }33 }34 assert_eq!(lit, CODE.count_ones());35 let carpet = designs::create(CODE, 3, 3, 0, 2)?;36 assert_eq!(carpet.types().sum(), 512);37 let under = board.height as f64 - TOP - WIDE;38 Grid::new(Frame::new(left, under, WIDE, WIDE), SIDE, SIDE, 0.0)39 .paint(&mut board, &carpet, |kind| (kind != 0).then_some(ink::blue()));40 save("site-math", &board)?;41 Ok(())42}