···5656 format!("\x1b[38;2;{};{};{}m\u{2588}\x1b[0m", r, g, b)
5757}
58585959-/// Build a leg row mask for the given body width and number of legs.
6060-/// Legs are distributed evenly across columns 1..(width-1) (one col inset from each edge).
6161-/// Each leg is 1 column wide. Returns a vec of bools (true = leg block).
6262-fn leg_mask(width: usize, numlegs: usize) -> Vec<bool> {
6363- let mut mask = vec![false; width];
6464- if numlegs == 0 || width < 3 {
6565- return mask;
5959+/// Build a leg row mask. Legs span from 1 col outside the body on each side,
6060+/// giving a total span of width+2. Returns a vec of bools of that total width,
6161+/// where index 0 = 1 col left of body. Also returns the offset (1) so the
6262+/// caller knows how to align it.
6363+fn leg_mask(width: usize, numlegs: usize) -> (Vec<bool>, usize) {
6464+ let overhang = 1usize;
6565+ let total = width + 2 * overhang;
6666+ let mut mask = vec![false; total];
6767+ if numlegs == 0 {
6868+ return (mask, overhang);
6669 }
67706868- // Usable span: columns 1 through width-2 (inset 1 from each edge)
6969- let span_start = 1usize;
7070- let span_end = width - 2; // inclusive
7171- let span = span_end - span_start + 1;
7171+ // Full span: 0 through total-1
7272+ let span = total;
72737374 if numlegs == 1 {
7474- // Center it
7575- mask[width / 2] = true;
7676- return mask;
7575+ mask[span / 2] = true;
7676+ return (mask, overhang);
7777 }
78787979- // Distribute numlegs evenly across the span
7979+ // Distribute numlegs evenly across the full span
8080 for i in 0..numlegs {
8181- let col = if numlegs == 1 {
8282- span_start + span / 2
8383- } else {
8484- span_start + (i * (span - 1)) / (numlegs - 1)
8585- };
8686- if col < width {
8181+ let col = (i * (span - 1)) / (numlegs - 1);
8282+ if col < total {
8783 mask[col] = true;
8884 }
8985 }
90869191- mask
8787+ (mask, overhang)
9288}
93899490fn main() {
···160156 }
161157162158 // -- Leg rows --
163163- let legs = leg_mask(width, numlegs);
159159+ let (legs, overhang) = leg_mask(width, numlegs);
164160 let effective_legsize = if numlegs == 0 { 0 } else { legsize };
165161166162 for _row in 0..effective_legsize {
167167- // Left padding (arm area)
168168- for _ in 0..arm_pad {
163163+ // Left padding: arm area minus overhang (legs can stick out 1 col past body)
164164+ let leg_pad = if arm_pad >= overhang { arm_pad - overhang } else { 0 };
165165+ for _ in 0..leg_pad {
169166 output.push_str(space);
170167 }
171171- for col in 0..width {
168168+ for col in 0..legs.len() {
172169 if legs[col] {
173170 output.push_str(&body_block);
174171 } else {