The caste system should have died millenia ago. Disgustingly prejudiced set of beliefs.
424 karma · joined September 7, 2022
Former SWE.
``` /// Implementation for converting an image to ASCII art. impl ToAsciiArt for ImageConverter { fn to_ascii_art(&self, options: Option<AsciiOptions>) -> String { let options = options.unwrap_or_default();
let target_width = options.width;
let target_height = options.height;
let width_ratio = self.image.width() as f32 / target_width as f32;
let height_ratio = self.image.height() as f32 / target_height as f32;
let mut ascii_art = String::with_capacity((target_width * target_height) as usize);
for y in 0..target_height {
for x in 0..target_width {
let start_x = (x as f32 * width_ratio) as u32;
let start_y = (y as f32 * height_ratio) as u32;
let mut total_r = 0;
let mut total_g = 0;
let mut total_b = 0;
for dy in 0..height_ratio as u32 {
for dx in 0..width_ratio as u32 {
let pixel = self.image.get_pixel(start_x + dx, start_y + dy);
let channels = pixel.channels();
total_r += channels[0] as u32;
total_g += channels[1] as u32;
total_b += channels[2] as u32;
}
}
let count = (width_ratio * height_ratio) as u32;
let avg_r = (total_r / count) as u8;
let avg_g = (total_g / count) as u8;
let avg_b = (total_b / count) as u8;
let luminance = (0.2126 * avg_r as f32 + 0.7152 * avg_g as f32 + 0.0722 * avg_b as f32) as u8;
let character = match luminance {
0..=31 => '#',
32..=63 => '@',
64..=95 => '8',
96..=127 => '&',
128..=159 => 'o',
160..=191 => ':',
192..=223 => '*',
224..=255 => '.',
};
ascii_art.push(character);
}
ascii_art.push('\n');
}
ascii_art
}
}
```Best of luck.
- Dictionary Brittanica.
Not that you asked, but I managed to mostly quit YT by making a bet with a friend about who could go the longest without it. Might work for you too.
What're your goals with lifting?
Source: the origins of political order, F. Fukuyama
Interested to hear from the SA members of HN on this one.
Law of unintended consequences I guess.