-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.h
82 lines (60 loc) · 1.84 KB
/
Color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _COLOR_H
#define _COLOR_H
class Color{
double red, green, blue, special;
public:
Color ();
Color (double,double,double, double);
// method functions
double getColorRed() { return red; }
double getColorGreen() { return green; }
double getColorBlue() { return blue; }
double getColorSpecial() { return special; }
double setColorRed(double redValue) { red = redValue; }
double setColorGreen(double greenValue) { green = greenValue; }
double setColorBlue(double blueValue) { blue = blueValue; }
double setColorSpecial(double specialValue) { special = specialValue; }
double brightness(){
return (red + green + blue)/3;
}
Color colorScalar(double scalar){
return Color (red*scalar, green*scalar, blue*scalar, special);
}
Color colorAdd(Color color){
return Color (red + color.getColorRed(), green + color.getColorGreen(), blue + color.getColorBlue(), special);
}
Color colorMultiply(Color color){
return Color (red * color.getColorRed(), green * color.getColorGreen(), blue * color.getColorBlue(), special);
}
Color colorAverage(Color color){
return Color ((red + color.getColorRed())/2, (green + color.getColorGreen())/2, (blue + color.getColorBlue())/2, special);
}
Color clip(){
double allLight = red + green + blue;
double excessLight = allLight - 3;
if ( excessLight > 0 ){
red = red + excessLight * (red/allLight);
green = green + excessLight * (green/allLight);
blue = blue + excessLight * (blue/allLight);
}
if (red > 1){ red = 1; }
if (green > 1){ green = 1; }
if (blue > 1){ blue = 1; }
if (red < 0){ red = 0; }
if (green < 0){ green = 0; }
if (blue < 0){ blue = 0; }
return Color ( red, green, blue, special );
}
};
Color::Color(){
red = 0.5;
green = 0.5;
blue = 0.5;
}
Color::Color( double r, double g, double b, double s){
red = r;
green = g;
blue = b;
special = s;
}
#endif