site-code.rs

1.0 kB · rust · 36 lines

1use mrlycore::errors::Result;2use mrlyfig::{grid, ink, save, Board, Frame, Grid};34const CELL: f64 = 51.0;56const CODE: [&str; 9] = [7    "000100000101000",8    "001100001101100",9    "011000001000110",10    "110000011000011",11    "100000010000001",12    "110000110000011",13    "011000100000110",14    "001101100001100",15    "000101000001000",16];1718fn main() -> Result<()> {19    let mut board = Board::square();20    let cols = CODE[0].len();21    let rows = CODE.len();22    let (w, h) = (CELL * cols as f64, CELL * rows as f64);23    let x = ((board.width as f64 - w) / 2.0).round();24    let y = ((board.height as f64 - h) / 2.0).round();25    let cells = Grid::new(Frame::new(x, y, w, h), cols, rows, 0.0);26    cells.carpet(&mut board, &grid::mask(&CODE, 1), ink::fg());27    for row in 0..rows {28        let col = 9 - row / 2;29        cells.fill(&mut board, col, row, ink::blue());30        if row % 2 == 1 {31            cells.fill(&mut board, col - 1, row, ink::blue());32        }33    }34    save("site-code", &board)?;35    Ok(())36}