Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn blend(colors: impl IntoIterator<Item = Hex>) -> Option<Hex> {
- let mut count = 0;
- let mut a_sum = 0.0;
- let mut b_sum = 0.0;
- let mut c_sum = 0.0;
- for color in colors {
- let Hex(a, b, c) = color;
- count += 1;
- a_sum += f64::from(a);
- b_sum += f64::from(b);
- c_sum += f64::from(c);
- }
- match count {
- 0 => None,
- _ => {
- let count = f64::from(count);
- Some(Hex(
- (a_sum / count).round() as u8,
- (b_sum / count).round() as u8,
- (c_sum / count).round() as u8,
- ))
- }
- }
- }
Add Comment
Please, Sign In to add comment