use super::Render;
static LEVEL10RAMP: &str = " .:-=+*#%@";
static LEVEL70RAMP: &str =
" .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
#[derive(Copy, Clone)]
pub enum AsciiRenders {
Level10,
Level70,
}
pub struct AsciiRender {
ramp: Vec<char>,
multiplier: f64,
}
impl AsciiRender {
pub fn new(render_type: AsciiRenders) -> Self {
let s = match render_type {
AsciiRenders::Level10 => LEVEL10RAMP,
AsciiRenders::Level70 => LEVEL70RAMP,
};
let ramp: Vec<_> = s.chars().collect();
let level = ramp.len();
let multiplier = (level as f64) / (f64::from(u8::max_value()) + 1.0);
Self { ramp, multiplier }
}
}
impl Render for AsciiRender {
type Pixel = char;
fn render_pixel(&self, _up: u8, _left: u8, gray: u8, _right: u8, _down: u8) -> Self::Pixel {
let index = (f64::from(gray) * self.multiplier).floor() as usize;
self.ramp[index]
}
}