-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolorgradient.h
More file actions
57 lines (44 loc) · 1009 Bytes
/
colorgradient.h
File metadata and controls
57 lines (44 loc) · 1009 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright © 2016 Mikko Ronkainen <firstname@mikkoronkainen.com>
// License: MIT, see the LICENSE file.
#pragma once
#include <cstdint>
#include <vector>
struct Color
{
Color()
{
}
Color(float r_, float g_, float b_, float a_ = 1.0f) : r(r_), g(g_), b(b_), a(a_)
{
}
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
float a = 1.0f;
static Color lerp(const Color& start, const Color& end, float alpha)
{
Color c;
c.r = start.r + (end.r - start.r) * alpha;
c.g = start.g + (end.g - start.g) * alpha;
c.b = start.b + (end.b - start.b) * alpha;
c.a = start.a + (end.a - start.a) * alpha;
return c;
}
};
struct ColorGradientSegment
{
Color startColor;
Color endColor;
uint32_t startIndex = 0;
uint32_t endIndex = 0;
};
class ColorGradient
{
public:
void addSegment(const Color& start, const Color& end, uint32_t length);
Color getColor(float alpha) const;
private:
uint32_t segmentCount = 0;
uint32_t totalLength = 0;
std::vector<ColorGradientSegment> segments;
};