-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemocoq.cpp
81 lines (73 loc) · 2.06 KB
/
democoq.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
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "democoq.h"
#include <QDebug>
typedef struct s_demo
{
int bulb;
QColor color;
float timer;
} t_demo;
t_demo demo[]=
{
{0, QColor(255, 0, 0), 0.5f},
{1, QColor(255, 0, 0), 0.5f},
{2, QColor(255, 0, 0), 0.5f},
{3, QColor(255, 0, 0), 0.5f},
{0, QColor(0, 255, 0), 0.5f},
{1, QColor(0, 255, 0), 0.5f},
{2, QColor(0, 255, 0), 0.5f},
{3, QColor(0, 255, 0), 0.5f},
{0, QColor(0, 0, 255), 0.5f},
{1, QColor(0, 0, 255), 0.5f},
{2, QColor(0, 0, 255), 0.5f},
{3, QColor(0, 0, 255), 0.5f},
{-1, QColor(0, 0, 0), 0.5f}
};
DemoCoq::DemoCoq() : QObject(NULL)
{
this->_anim.restart();
QList<KeyFrame> anim1;
anim1 << KeyFrame(3, QColor(255, 0, 0))
<< KeyFrame(3, QColor(0, 255, 0))
<< KeyFrame(3, QColor(0, 0, 255));
QList<KeyFrame> anim2;
anim2 << KeyFrame(3, QColor(0, 255, 0))
<< KeyFrame(3, QColor(0, 0, 255))
<< KeyFrame(3, QColor(255, 0, 0));
QList<KeyFrame> anim3;
anim3 << KeyFrame(3, QColor(0, 0, 255))
<< KeyFrame(3, QColor(255, 0, 0))
<< KeyFrame(3, QColor(0, 255, 0));
QList<KeyFrame> anim4;
anim4 << KeyFrame(3, QColor(255, 255, 0))
<< KeyFrame(3, QColor(0, 255, 255))
<< KeyFrame(3, QColor(255, 0, 255));
this->_frames << anim1 << anim2 << anim3 << anim4;
}
void DemoCoq::addAPIConnector(APIConnector *api)
{
this->_apis.append(api);
}
void DemoCoq::updateColor()
{
auto it = this->_frames.begin();
float time = float(this->_anim.elapsed()) / 1000;
for (auto itAPI : this->_apis) {
float incr = 0;
QColor color(0, 0, 0);
for (auto itFrames : *it) {
if (time >= incr && time < incr + itFrames.duration) {
color = itFrames.color;
break;
}
incr += itFrames.duration;
}
itAPI->setColor(color);
qDebug() << color << time;
++it;
}
}
DemoCoq::KeyFrame::KeyFrame(float duration, const QColor &color)
{
this->duration = duration;
this->color = color;
}