[ create a new paste ] login | about

Link: http://codepad.org/wRqLchSn    [ raw code | output | fork ]

minitech - C++, pasted on Feb 9:
#include <iostream>

typedef int byte;

class Color {
     byte r;
     byte g;
     byte b;
     byte a;
public:
     Color() {}
     Color(byte r, byte g, byte b);
     Color(byte r, byte g, byte b, byte a);
     byte set_R(byte r);
     byte set_G(byte g);
     byte set_B(byte b);
     byte set_A(byte a);
     byte get_R();
     byte get_G();
     byte get_B();
     byte get_A();
     int get_Color();
     int set_Color(int c);
};

Color::Color(byte r, byte g, byte b) {
      this->set_R(r);
      this->set_G(g);
      this->set_B(b);
}

Color::Color(byte r, byte g, byte b, byte a) {
      this->set_R(r);
      this->set_G(g);
      this->set_B(b);
      this->set_A(a);
}

byte Color::get_R() {
      return this->r;
}

byte Color::get_G() {
      return this->g;
}

byte Color::get_B() {
      return this->b;
}

byte Color::get_A() {
      return this->a;
}

byte Color::set_R(byte r) {
      return this->r = r;
}

byte Color::set_G(byte g) {
      return this->g = g;
}

byte Color::set_B(byte b) {
      return this->b = b;
}

byte Color::set_A(byte a) {
      return this->a = a;
}

int Color::get_Color() {
      return (this->get_A() << 24) | (this->get_R() << 16) | (this->get_G() << 8) | this->get_B();
}

int Color::set_Color(int c) {
      this->set_A((byte)(c >> 24));
      this->set_R((byte)((c >> 16) && 0xff));
      this->set_G((byte)((c >> 8) && 0xff));
      this->set_B((byte)(c && 0xff));
      return c;
}

int main() {
     Color *c = new Color;
     cout << "Setting R to " << c->set_R(255) << "...\n";
     cout << "Setting G to " << c->set_G(255) << "...\n";
     cout << "Setting B to " << c->set_B(255) << "...\n";
     cout << "Setting A to " << c->set_A(255) << "...\n";
     cout.setf(ios::hex);
     cout << "Color is: 0x" << c->get_Color() << "\n";
     cout << "Setting color to 0x" << c->set_Color(0) << "...\n";
     cout << "c->get_R() = " << c->get_R() << ".";
     delete c;
     return 0;
}


Output:
1
2
3
4
5
6
7
Setting R to 255...
Setting G to 255...
Setting B to 255...
Setting A to 255...
Color is: 0x-1
Setting color to 0x0...
c->get_R() = 0.


Create a new paste based on this one


Comments: