-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rainbow.cpp
68 lines (59 loc) · 1.33 KB
/
Rainbow.cpp
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
//
// A Sample of EggAche Graphics Library
// By BOT Man, 2016
//
#include "../src/EggAche.h"
#include <vector>
#include <tuple>
int main (int argc, char *argv[])
{
using namespace EggAche;
const auto wndSize = 300;
Window window (wndSize, wndSize, "Little Rainbow");
Canvas canvas (wndSize, wndSize);
window.SetBackground (&canvas);
std::vector<std::tuple<unsigned, unsigned, unsigned>> colors
{
{255, 0, 0},
{255, 165, 0},
{255, 255, 0},
{0, 255, 0},
{0, 127, 255},
{0, 0, 255},
{139, 0, 255}
};
auto cColor = colors.size ();
double anglePerSeg = 360.0 / cColor;
canvas.SetPen (0, 0, 0, 0);
auto DrawRainbow = [&] (double angleBeg,
unsigned r,
unsigned g,
unsigned b)
{
canvas.SetBrush (false, r, g, b);
canvas.DrawPie (0, 0, wndSize, wndSize,
angleBeg, anglePerSeg);
};
bool isStop = false;
window.OnClick ([&] (Window *, int, int)
{
isStop = !isStop;
});
auto offset = 0;
const auto offsetCount = 200;
while (!window.IsClosed ())
if (!isStop)
{
if (offset < offsetCount) offset++;
else offset = 0;
canvas.Clear ();
for (size_t i = 0; i < cColor; i++)
DrawRainbow (anglePerSeg * i +
offset * 360.0 / offsetCount,
std::get<0> (colors[i]),
std::get<1> (colors[i]),
std::get<2> (colors[i]));
window.Refresh ();
}
return 0;
}