-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColorInterpolate.cpp
More file actions
40 lines (30 loc) · 865 Bytes
/
ColorInterpolate.cpp
File metadata and controls
40 lines (30 loc) · 865 Bytes
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
#include <wx/wx.h>
#include "ColorInterpolate.h"
void ColorInterpolate::setColors(unsigned char r1_,
unsigned char g1_,
unsigned char b1_,
unsigned char r2_,
unsigned char g2_,
unsigned char b2_)
{
r1 = r1_;
g1 = g1_;
b1 = b1_;
r2 = r2_;
g2 = g2_;
b2 = b2_;
r_range = static_cast<double>(r2 - r1);
g_range = static_cast<double>(g2 - g1);
b_range = static_cast<double>(b2 - b1);
}
wxColour* ColorInterpolate::color(const double x) const
{
if (x <= 0.0)
return new wxColour(r1,g1,b1);
if (x >= 1.0)
return new wxColour(r2,g2,b2);
const unsigned char r = r1 + static_cast<unsigned char>(x*r_range);
const unsigned char g = g1 + static_cast<unsigned char>(x*g_range);
const unsigned char b = b1 + static_cast<unsigned char>(x*b_range);
return new wxColour(r, g, b);
}