paper-sequence-census.rs
2.1 kB · rust · 77 lines
1use mrlycore::errors::Result;2use mrlycore::Color;3use mrlyfig::board::Frame;4use mrlyfig::{ink, save, Board, Grid};5use mrlymath::two::designs;67const SIDE: usize = 5;8const GAP: f64 = 0.14;910fn outline(board: &mut Board, frame: Frame, thick: f64) {11 board.polyline(12 &[13 (frame.x, frame.y),14 (frame.x + frame.w, frame.y),15 (frame.x + frame.w, frame.y + frame.h),16 (frame.x, frame.y + frame.h),17 (frame.x, frame.y),18 ],19 thick,20 ink::line(),21 );22}2324fn panel(board: &mut Board, frame: Frame, code: u128, tone: Color) -> Result<usize> {25 let design = designs::create(code, SIDE, 1, 0, 2)?;26 let types = design.types();27 let grid = Grid::new(frame, SIDE, SIDE, GAP);28 let mut filled = 0usize;29 for row in 0..SIDE {30 for col in 0..SIDE {31 if types.get(&[row, col]) == 0 {32 continue;33 }34 filled += 1;35 let (x, y, w, h) = grid.cell(col, row);36 board.rect(x, y, w, h, tone);37 }38 }39 let pitch = frame.w / SIDE as f64;40 outline(41 board,42 Frame::new(frame.x + pitch, frame.y + pitch, 3.0 * pitch, 3.0 * pitch),43 2.0,44 );45 Ok(filled)46}4748fn main() -> Result<()> {49 let codes = [1u128, 3, 7, 9, 11, 15];50 let tones = [51 ink::blue(),52 ink::blue(),53 ink::blue(),54 ink::indigo(),55 ink::indigo(),56 ink::indigo(),57 ];58 let mut board = Board::square();59 let frame = board.frame(0.08);60 let height = frame.h * 0.80;61 let block = Frame::new(frame.x, frame.y + (frame.h - height) / 2.0, frame.w, height);62 let mut counts = Vec::new();63 for (band, row) in block.rows(2).iter().enumerate() {64 for (index, slot) in row.cols(3).iter().enumerate() {65 let place = band * 3 + index;66 counts.push(panel(67 &mut board,68 slot.inset(16.0),69 codes[place],70 tones[place],71 )?);72 }73 }74 assert_eq!(counts, vec![9, 15, 21, 13, 19, 25]);75 save("paper-sequence-census", &board)?;76 Ok(())77}