// FILE: color.cpp // written for the course 2172, 1999 // #include "color.h" // constant colors // transperent, clear or eraser const color clear(-1,-1,-1); const color white(255,255,255); const color black(0,0,0); // rainbow const color red(255,0,0); const color green(0,255,0); const color blue(0,0,255); // inverses const color cyan(0,255,255); const color yellow(255,255,0); const color magenta(255,0,255); // constructor color::color(short r,short g,short b): _red((short)(r<0 || g<0 || b<0 ?-1:r%256)), _green((short)(r<0 || g<0 || b<0 ?-1:g%256)), _blue((short)(r<0 || g<0 || b<0 ?-1:b%256)) { } // properties short color::red() const { return _red; } short color::blue() const { return _blue; } short color::green() const { return _green; } bool operator==(const color& c1,const color& c2) { return ( c1.red() == c2.red() && c1.green() == c2.green() && c1.blue() == c2.blue()); } bool operator!=(const color& c1,const color& c2) { return ( c1.red() != c2.red() || c1.green() != c2.green() || c1.blue() != c2.blue()); } ostream& operator<<(ostream& os, const color& c) { return os << '(' << c._red << ',' << c._green << ',' << c._blue << ')'; }