pub struct Geodesic {
pub start: StartHint,
pub bridge: u16,
}Expand description
Reveal by tracing the art’s skeleton.
The ink is first thinned to a one-cell-wide skeleton (Zhang-Suen), the centerline a pen would draw. Each connected piece of that skeleton is traced tip to tip by geodesic distance, a double breadth-first sweep finding the two ends of its longest path, and the pieces are ordered along the art’s dominant axis. So a snake paints head to tail, a filled dragon paints down its spine, and a multi-letter logo paints letter by letter in reading order, with no per-art tuning.
Hand-drawn ASCII is usually many separate strokes, not one connected line, so the
trace bridges small gaps to stitch a broken stroke into one piece; art that is
already whole is traced strictly, with no shortcuts (see Geodesic::bridge).
The flesh around the skeleton inherits the value of its nearest centerline cell, a Voronoi flood, so detail reveals in step with the part of the spine it hangs from; where the skeleton is a mere dot, as in a solid blob, the fill radiates out from the middle. Finally the values are rank-transformed to evenly spaced ranks, so the reveal keeps its order yet tracks the progress bar with no dead zone at either end.
Fields§
§start: StartHintWhich tip of the spine the reveal begins from.
bridge: u16The largest gap, in blank cells, the spine may step across. Bridging only
engages when the art is actually fragmented (see STRICT_CONNECTED_MIN),
so it stitches the separate strokes of hand-drawn ASCII into one body
without ever adding shortcuts to art that was already connected. 0
disables it.
Implementations§
Source§impl Geodesic
impl Geodesic
Sourcepub fn diagnose(&self, art: &Art) -> GeodesicReport
pub fn diagnose(&self, art: &Art) -> GeodesicReport
Inspect the art without building a full rank map.
Examples found in repository?
20fn main() {
21 let args: Vec<String> = std::env::args().skip(1).collect();
22 let snapshots = args.iter().any(|a| a == "--snapshots");
23
24 let art = match arg_value(&args, "--art") {
25 Some(path) => match std::fs::read_to_string(&path) {
26 Ok(text) => Art::parse(&text),
27 Err(e) => {
28 eprintln!("inkling: could not read {path}: {e}");
29 std::process::exit(1);
30 }
31 },
32 None => Art::parse(&serpent(64, 13)),
33 };
34
35 let ordering = Geodesic::default();
36 let GeodesicReport {
37 ink_cells,
38 connected_cells,
39 skeleton_cells,
40 pieces,
41 spine_length,
42 } = ordering.diagnose(&art);
43 let ranks = ordering.rank(&art);
44
45 eprintln!(
46 "inkling · {ink_cells} ink cells ({:.0}% 8-connected) · \
47 {skeleton_cells}-cell skeleton in {pieces} piece(s) · spine {spine_length}",
48 100.0 * connected_cells as f32 / ink_cells.max(1) as f32,
49 );
50
51 // Headless / piped / explicit: print staged text frames and exit.
52 if snapshots || !std::io::stdout().is_terminal() {
53 for p in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] {
54 println!("\n── progress {:>3.0}% {}", p * 100.0, "─".repeat(28));
55 print!("{}", frame::to_string(&art, &ranks, p));
56 }
57 return;
58 }
59
60 #[cfg(feature = "terminal")]
61 {
62 use inkling::{
63 easing::Easing,
64 render::{animate, Style},
65 };
66 use std::time::Duration;
67 if let Err(e) = animate(
68 &art,
69 &ranks,
70 Style::default(),
71 Duration::from_millis(3500),
72 Easing::EaseInOutCubic,
73 ) {
74 eprintln!("inkling: render error: {e}");
75 }
76 }
77}