blog-launching-mrlyprod-org.rs
1.1 kB · rust · 42 lines
1use mrlycore::errors::Result;2use mrlycore::Color;3use mrlyfig::{ink, save, Board, Grid};45const SIDE: usize = 8;6const GUTTER: f64 = 3.0;7const EDGES: [usize; 4] = [28, 40, 60, 64];89fn tones() -> [Color; 4] {10 [ink::blue(), ink::yellow(), ink::green(), ink::ground()]11}1213fn band(index: usize) -> usize {14 EDGES.iter().position(|edge| index < *edge).unwrap_or(3)15}1617fn main() -> Result<()> {18 let mut board = Board::square();19 let frame = board.frame(0.08);20 board.rect(frame.x, frame.y, frame.w, frame.h, ink::line());21 let grid = Grid::new(frame, SIDE, SIDE, 0.0);22 let tones = tones();23 let mut counts = [0usize; 4];24 for row in 0..SIDE {25 for col in 0..SIDE {26 let index = row * SIDE + col;27 let slot = band(index);28 let (x, y, w, h) = grid.cell(col, row);29 board.rect(30 x + GUTTER / 2.0,31 y + GUTTER / 2.0,32 w - GUTTER,33 h - GUTTER,34 tones[slot],35 );36 counts[slot] += 1;37 }38 }39 assert_eq!(counts, [28, 12, 20, 4]);40 save("blog-launching-mrlyprod-org", &board)?;41 Ok(())42}