From 7bd41df3e99356f5cafe1eadcb3d4d7cd4026cc8 Mon Sep 17 00:00:00 2001 From: Julien WITTOUCK Date: Sun, 14 Jun 2026 17:44:13 +0000 Subject: [PATCH] 🔨 : add big-text generation script --- big-text/Cargo.lock | 16 ++++++++++++++++ big-text/Cargo.toml | 7 +++++++ big-text/src/main.rs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 file(s) changed, 115 insertion(s)(+), 0 deletion(s)(-) diff --git a/big-text/Cargo.lock b/big-text/Cargo.lock new file mode 100644 --- /dev/null +++ b/big-text/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "big-text" +version = "0.1.0" +dependencies = [ + "font8x8", +] + +[[package]] +name = "font8x8" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e" diff --git a/big-text/Cargo.toml b/big-text/Cargo.toml new file mode 100644 --- /dev/null +++ b/big-text/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "big-text" +version = "0.1.0" +edition = "2021" + +[dependencies] +font8x8 = "0.3" diff --git a/big-text/src/main.rs b/big-text/src/main.rs new file mode 100644 --- /dev/null +++ b/big-text/src/main.rs @@ -0,0 +1,92 @@ +use font8x8::UnicodeFonts; +use std::env; + +const SEXANT_SYMBOLS: [char; 64] = [ + ' ', '🬀', '🬁', '🬂', '🬃', '🬄', '🬅', '🬆', '🬇', '🬈', '🬉', '🬊', '🬋', '🬌', '🬍', '🬎', + '🬏', '🬐', '🬑', '🬒', '🬓', '▌', '🬔', '🬕', '🬖', '🬗', '🬘', '🬙', '🬚', '🬛', '🬜', '🬝', + '🬞', '🬟', '🬠', '🬡', '🬢', '🬣', '🬤', '🬥', '🬦', '🬧', '▐', '🬨', '🬩', '🬪', '🬫', '🬬', + '🬭', '🬮', '🬯', '🬰', '🬱', '🬲', '🬳', '🬴', '🬵', '🬶', '🬷', '🬸', '🬹', '🬺', '🬻', '█', +]; + +const QUADRANT_SYMBOLS: [char; 16] = [ + ' ', '▘', '▝', '▀', '▖', '▌', '▞', '▛', '▗', '▚', '▐', '▜', '▄', '▙', '▟', '█', +]; + +fn get_sextant(tl: u8, tr: u8, ml: u8, mr: u8, bl: u8, br: u8) -> char { + let idx = (if tl > 0 { 1 } else { 0 }) + + (if tr > 0 { 2 } else { 0 }) + + (if ml > 0 { 4 } else { 0 }) + + (if mr > 0 { 8 } else { 0 }) + + (if bl > 0 { 16 } else { 0 }) + + (if br > 0 { 32 } else { 0 }); + SEXANT_SYMBOLS[idx] +} + +fn get_quadrant(tl: u8, tr: u8, bl: u8, br: u8) -> char { + let idx = (if tl > 0 { 1 } else { 0 }) + + (if tr > 0 { 2 } else { 0 }) + + (if bl > 0 { 4 } else { 0 }) + + (if br > 0 { 8 } else { 0 }); + QUADRANT_SYMBOLS[idx] +} + +fn render_text(text: &str, use_quadrant: bool) -> String { + let glyphs: Vec<[u8; 8]> = text + .chars() + .map(|c| { + font8x8::BASIC_FONTS + .get(c) + .or_else(|| font8x8::LATIN_FONTS.get(c)) + .unwrap_or([0u8; 8]) + }) + .collect(); + + let mut out = String::new(); + + if use_quadrant { + for y in (0..8).step_by(2) { + for glyph in &glyphs { + for x in (0..8).step_by(2) { + let tl = glyph[y] & (1 << x); + let tr = glyph[y] & (1 << (x + 1)); + let bl = if y + 1 < 8 { glyph[y + 1] & (1 << x) } else { 0 }; + let br = if y + 1 < 8 { glyph[y + 1] & (1 << (x + 1)) } else { 0 }; + out.push(get_quadrant(tl, tr, bl, br)); + } + } + out.push('\n'); + } + } else { + for y in (0..8).step_by(3) { + for glyph in &glyphs { + for x in (0..8).step_by(2) { + let tl = glyph[y] & (1 << x); + let tr = glyph[y] & (1 << (x + 1)); + let ml = if y + 1 < 8 { glyph[y + 1] & (1 << x) } else { 0 }; + let mr = if y + 1 < 8 { glyph[y + 1] & (1 << (x + 1)) } else { 0 }; + let bl = if y + 2 < 8 { glyph[y + 2] & (1 << x) } else { 0 }; + let br = if y + 2 < 8 { glyph[y + 2] & (1 << (x + 1)) } else { 0 }; + out.push(get_sextant(tl, tr, ml, mr, bl, br)); + } + } + out.push('\n'); + } + } + out +} + +fn main() { + let args: Vec = env::args().collect(); + if args.len() < 2 { + eprintln!("Usage: {} [-q] ", args[0]); + std::process::exit(1); + } + let mut text_start = 1; + let mut use_quadrant = false; + if args[1] == "-q" { + use_quadrant = true; + text_start = 2; + } + let text = &args[text_start..].join(" "); + print!("{}", render_text(text, use_quadrant)); +} -- tangled.sh