demo-morse.rs

1.0 kB · rust · 33 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board};3use mrlynum::morse::{lift, Lift};45const SIDE: usize = 32;67fn main() -> Result<()> {8    let mut board = Board::square();9    let area = board.frame(0.08);10    let signs = lift(Lift::Parity, SIDE);11    assert_eq!(signs.len(), SIDE * SIDE);12    assert_eq!(lift(Lift::Xor, SIDE), signs);13    let cool = signs.iter().filter(|&&sign| sign == 1).count();14    assert_eq!(cool, SIDE * SIDE / 2);15    let scale = (area.w / SIDE as f64).floor().max(1.0);16    let block = SIDE as f64 * scale;17    let ox = ((board.width as f64 - block) / 2.0).round();18    let oy = ((board.height as f64 - block) / 2.0).round();19    for row in 0..SIDE {20        for col in 0..SIDE {21            let tone = if signs[row * SIDE + col] == 0 {22                ink::orange()23            } else {24                ink::blue()25            };26            let x = ox + col as f64 * scale;27            let y = oy + row as f64 * scale;28            board.rect(x, y, scale, scale, tone);29        }30    }31    save("demo-morse", &board)?;32    Ok(())33}