Guest User

Untitled

a guest
Jan 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. fn blend(colors: impl IntoIterator<Item = Hex>) -> Option<Hex> {
  2. let mut count = 0;
  3. let mut a_sum = 0.0;
  4. let mut b_sum = 0.0;
  5. let mut c_sum = 0.0;
  6.  
  7. for color in colors {
  8. let Hex(a, b, c) = color;
  9.  
  10. count += 1;
  11. a_sum += f64::from(a);
  12. b_sum += f64::from(b);
  13. c_sum += f64::from(c);
  14. }
  15.  
  16. match count {
  17. 0 => None,
  18. _ => {
  19. let count = f64::from(count);
  20.  
  21. Some(Hex(
  22. (a_sum / count).round() as u8,
  23. (b_sum / count).round() as u8,
  24. (c_sum / count).round() as u8,
  25. ))
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment