use super::*;
impl LifeField {
pub fn render_lines(&self, char_width: usize, char_height: usize) -> Vec<Line<'static>> {
let mut lines = Vec::with_capacity(char_height);
for char_y in 0..char_height {
let mut text = String::with_capacity(char_width);
for char_x in 0..char_width {
let dot_x = char_x * 2;
let dot_y = char_y * 4;
text.push(self.braille_char(dot_x, dot_y));
}
lines.push(Line::from(Span::raw(text)));
}
lines
}
pub fn braille_char(&self, dot_x: usize, dot_y: usize) -> char {
let mut bits = 0u32;
for local_y in 0..4 {
for local_x in 0..2 {
let x = dot_x + local_x;
let y = dot_y + local_y;
if x < self.width && y < self.height && self.cells[self.index(x, y)] {
bits |= match (local_x, local_y) {
(0, 0) => 0x01,
(0, 1) => 0x02,
(0, 2) => 0x04,
(0, 3) => 0x40,
(1, 0) => 0x08,
(1, 1) => 0x10,
(1, 2) => 0x20,
(1, 3) => 0x80,
_ => 0,
};
}
}
}
char::from_u32(0x2800 + bits).unwrap_or(' ')
}
}