Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Color {
- public:
- Color();
- Color(unsigned color);
- Color(unsigned R, unsigned G, unsigned B);
- std::vector<unsigned> RGB_vec();
- operator unsigned() {
- return hexa_merging(r, g, b);
- }
- constexpr unsigned R() const noexcept {
- return r;
- }
- constexpr unsigned G() const noexcept {
- return g;
- }
- constexpr unsigned B() const noexcept {
- return b;
- }
- private:
- void hexa_spliting(unsigned hexa);
- unsigned hexa_merging(unsigned rr, unsigned gg, unsigned bb);
- unsigned r;
- unsigned g;
- unsigned b;
- };
- Color::Color()
- : r{0},
- g{0},
- b{0}
- {
- }
- Color::Color(unsigned color)
- {
- hexa_spliting(color);
- }
- Color::Color(unsigned R, unsigned G, unsigned B)
- : r{R},
- g{G},
- b{B}
- {
- }
- std::vector<unsigned> Color::RGB_vec()
- {
- return {r, g, b};
- }
- void Color::hexa_spliting(unsigned hexa)
- {
- r = (hexa >> 16) & 0xFF;
- g = (hexa >> 8) & 0xFF;
- b = hexa & 0xFF;
- }
- unsigned Color::hexa_merging(unsigned rr, unsigned gg, unsigned bb)
- {
- auto R_ = rr;
- auto G_ = gg;
- auto B_ = bb;
- auto a_ = R_ & 0xF;
- auto b_ = (R_ >> 4) & 0xF;
- auto c_ = G_ & 0xF;
- auto d_ = (G_ >> 4) & 0xF;
- auto e_ = B_ & 0xF;
- auto f_ = (B_ >> 4) & 0xF;
- return e_ + (f_*16) + (c_*16*16) + (d_*16*16*16) + (a_*16*16*16*16) + (b_*16*16*16*16*16);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement