Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <array>
  2. #include <cmath>
  3.  
  4. class Potion
  5. {
  6. public:
  7. std::array<unsigned char, 3> color;
  8. unsigned int volume;
  9.  
  10. Potion(const std::array<unsigned char, 3> &color, const unsigned int &volume): color(color), volume(volume)
  11. {}
  12.  
  13. Potion mix(const Potion& other)
  14. {
  15. unsigned int newVolume = volume + other.volume;
  16.  
  17. std::array<unsigned char, 3> newColor;
  18. for(int i = 0; i < 3; i++)
  19. {
  20. auto component = (float)(color.at(i) * volume + other.color.at(i) * other.volume) / newVolume;
  21. newColor.at(i) = ceil(component);
  22. }
  23.  
  24. return Potion(newColor, newVolume);
  25. }
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement