-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLinearEffect.cpp
35 lines (28 loc) · 911 Bytes
/
LinearEffect.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
/*
* File: LinearEffect.cpp
* Author: chlorek
*
* Created on June 11, 2018, 12:38 AM
*/
#include "LinearEffect.hpp"
namespace colorsair {
LinearEffect::LinearEffect(std::chrono::milliseconds duration)
: Effect(), begin(std::chrono::system_clock::now()), duration(duration) {
}
LinearEffect::LinearEffect(const LinearEffect& orig)
: begin(orig.begin), duration(orig.duration) {
}
LinearEffect::~LinearEffect() {
}
float LinearEffect::tick() {
auto diff = std::chrono::system_clock::now() - begin;
if(diff >= duration) {
begin = std::chrono::system_clock::now();
diff = duration;
}
float progress = (float)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() / duration.count();
if(progress > 1)
progress = 1;
return progress;
}
}