-
Notifications
You must be signed in to change notification settings - Fork 1
/
Color.h
43 lines (36 loc) · 971 Bytes
/
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
/*
* File: Color.h
* Author: caos
*
* Created on June 18, 2015, 11:48 PM
*/
#ifndef COLOR_H
#define COLOR_H
#include <cstdlib>
class Color
{
public:
Color(int _r, int _g, int _b) : r((_r>255)?255:_r), g((_g>255)?255:_g), b((_b>255)?255:_b) {} ;
Color()
{
r = rand()%256;
g = rand()%256;
b = rand()%256;
};
int getR() { return r;} ;
int getG() { return g;} ;
int getB() { return b;} ;
static Color multiply(const Color& lhs, float coeff) { return Color(lhs.r*coeff, lhs.g*coeff, lhs.b*coeff);};
static Color multiply(const Color& lhs, const Color& rhs)
{
Color res;
res.r = (lhs.r*rhs.r)/255;
res.g = (lhs.g*rhs.g)/255;
res.b = (lhs.b*rhs.b)/255;
return res;
};
static Color add(const Color& lhs, const Color& rhs) { return Color(lhs.r+rhs.r, lhs.g+rhs.g, lhs.b+rhs.b);};
private:
int r, g, b;
};
#endif /* COLOR_H */