sources:


website:
more info here


screenshot:
studies/grafik2/Computergrafik-Code3/Aufgabe8/color.h
download file

  1 //
  2 // Computergraphik II
  3 // Prof. Dr. Juergen Doellner
  4 // Wintersemester 2001/2002
  5 //
  6 // Rahmenprogramm fuer Aufgabenzettel 3
  7 //
  8 // Autoren: Florian Kirsch (kirsch@hpi.uni-potsdam.de)
  9 // Marc Nienhaus (nienhaus@hpi.uni-potsdam.de)
 10 // Juergen Doellner (doellner@hpi.uni-potsdam.de)
 11 //
 12
 13 #ifndef CG_COLOR_H
 14 #define CG_COLOR_H
 15
 16 #include <iostream.h>
 17
 18 class Color {
 19 public:
 20     Color(double grey=0);
 21     Color(double red, double green, double blue, double alpha = 1.0);
 22         /* A color is specified by the red, green, and blue coefficients and the alpha (e.g., transmission) coefficient. All coefficients are clamped to the double interval [0.0, 1.0]. */
 23
 24     bool operator==(const Color&) const;
 25     bool operator!=(const Color&) const;
 26
 27     Color operator+(const Color& col) const;
 28     Color operator-(const Color& col) const;
 29     Color operator*(double coef) const;
 30         /* These operators transform the red, green, and blue components. They do *not* apply to the alpha value. The result of each operation is clamped to [0.0, 1.0]. */
 31
 32     double operator[](int i) const;
 33     double& operator[](int i);
 34         /* The four components are indexed by R=[0], G=[1], B=[2], and A=[3]. The index is checked for out of range errors. */
 35
 36     static Color hsv(double hue, double saturation, double value, double alpha=1.0);
 37     double hue() const;
 38     double saturation() const;
 39     double value() const;
 40         /* Provide the conversion between the RGB and HSV color models. `hsv' can specify achromatic (gray-scale) colors by setting `s' to 0.0 and `v' to the gray coefficient between [0,1]. The `hue' factor must be specified in degrees in the range [-360,360]. If hue is smaller 0, 360 degrees are added before the conversion is invoked. Both saturation and value must be in the range [0,1]. */
 41
 42     static Color InterpolateRGB(const Color& from, const Color& to, double dPercentage);
 43     static Color InterpolateHSV(const Color& from, const Color& to, double dPercentage, bool bClockwise = true);
 44
 45     friend ostream& operator<<(ostream&, const Color&);
 46     friend istream& operator>>(istream&, Color&);
 47
 48 private:
 49     double rgba_[4];
 50 };
 51
 52 #endif // CG_COLOR_H
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67