Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <cmath>
- class Potion
- {
- public:
- std::array<unsigned char, 3> color;
- unsigned int volume;
- Potion(const std::array<unsigned char, 3> &color, const unsigned int &volume): color(color), volume(volume)
- {}
- Potion mix(const Potion& other)
- {
- unsigned int newVolume = volume + other.volume;
- std::array<unsigned char, 3> newColor;
- for(int i = 0; i < 3; i++)
- {
- auto component = (float)(color.at(i) * volume + other.color.at(i) * other.volume) / newVolume;
- newColor.at(i) = ceil(component);
- }
- return Potion(newColor, newVolume);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement