daily pastebin goal
93%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Color {
  2. public:
  3.     Color();
  4.     Color(unsigned color);
  5.     Color(unsigned R, unsigned G, unsigned B);
  6.  
  7.     std::vector<unsigned> RGB_vec();
  8.  
  9.     operator unsigned() {
  10.         return hexa_merging(r, g, b);
  11.     }
  12.  
  13.     constexpr unsigned R() const noexcept {
  14.         return r;
  15.     }
  16.  
  17.     constexpr unsigned G() const noexcept {
  18.         return g;
  19.     }
  20.  
  21.     constexpr unsigned B() const noexcept {
  22.         return b;
  23.     }
  24. private:
  25.     void hexa_spliting(unsigned hexa);
  26.     unsigned hexa_merging(unsigned rr, unsigned gg, unsigned bb);
  27.  
  28.     unsigned r;
  29.     unsigned g;
  30.     unsigned b;
  31. };
  32.  
  33. Color::Color()
  34. : r{0},
  35.   g{0},
  36.   b{0}
  37. {
  38.  
  39. }
  40.  
  41. Color::Color(unsigned color)
  42. {
  43.     hexa_spliting(color);
  44. }
  45.  
  46. Color::Color(unsigned R, unsigned G, unsigned B)
  47. : r{R},
  48.   g{G},
  49.   b{B}
  50. {
  51.  
  52. }
  53.  
  54.  
  55. std::vector<unsigned> Color::RGB_vec()
  56. {
  57.     return {r, g, b};
  58. }
  59.  
  60. void Color::hexa_spliting(unsigned hexa)
  61. {
  62.     r = (hexa >> 16) & 0xFF;
  63.     g = (hexa >> 8) & 0xFF;
  64.     b = hexa & 0xFF;
  65. }
  66.  
  67. unsigned Color::hexa_merging(unsigned rr, unsigned gg, unsigned bb)
  68. {
  69.     auto R_ = rr;
  70.     auto G_ = gg;
  71.     auto B_ = bb;
  72.  
  73.     auto a_ = R_ & 0xF;
  74.     auto b_ = (R_ >> 4) & 0xF;
  75.     auto c_ = G_ & 0xF;
  76.     auto d_ = (G_ >> 4) & 0xF;
  77.     auto e_ = B_ & 0xF;
  78.     auto f_ = (B_ >> 4) & 0xF;
  79.     return e_ + (f_*16) + (c_*16*16) + (d_*16*16*16) + (a_*16*16*16*16) + (b_*16*16*16*16*16);
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top