use super::Render;
static MOON_CHARS: [[char; 2]; 5] = [
['🌕', '🌕'],
['🌖', '🌔'],
['🌗', '🌓'],
['🌘', '🌒'],
['🌑', '🌑'],
];
pub struct MoonRender {
multiplier: f64,
}
impl MoonRender {
pub fn new() -> Self {
let multiplier = MOON_CHARS.len() as f64 / 256.0;
Self { multiplier }
}
}
impl Render for MoonRender {
type Pixel = char;
fn render_pixel(&self, _up: u8, left: u8, gray: u8, right: u8, _down: u8) -> Self::Pixel {
if gray == 0 {
return MOON_CHARS[MOON_CHARS.len() - 1][0];
}
let index = (f64::from(255 - gray) * self.multiplier).floor() as usize;
if left < right {
MOON_CHARS[index][1]
} else {
MOON_CHARS[index][0]
}
}
}