-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.h
46 lines (35 loc) · 1.01 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
#ifndef COLOR_H_
#define COLOR_H_
#include <cmath>
#include "util.h"
struct Color {
int red;
int green;
int blue;
// Add some nice functionality to this later on.
Color(int r, int g, int b) {
red = clamp(0, 255, r);
green = clamp(0, 255, g);
blue = clamp(0, 255, b);
}
Color operator* (double scale) const {
return Color(static_cast<int>(this->red*scale),
static_cast<int>(this->green*scale),
static_cast<int>(this->blue*scale));
}
Color operator+ (const Color& c) const {
return Color(this->red + c.red,
this->green + c.green,
this->blue + c.blue);
}
Color operator- (const Color& c) const {
return Color(this->red - c.red,
this->green - c.green,
this->blue - c.blue);
}
Color tint(double scale) const {
const Color c{0xFF, 0xFF, 0xFF};
return *this + (c-*this)*scale;
}
};
#endif