FastLED 3.9.3
Loading...
Searching...
No Matches
transition.h
1#pragma once
2
3#include <stdint.h>
4#include "namespace.h"
5
6FASTLED_NAMESPACE_BEGIN
7
8// Logic to control the progression of a transition over time.
9class Transition {
10public:
11 Transition() : mStart(0), mDuration(0), mNotStarted(true) {}
12 ~Transition() {}
13
14 uint8_t getProgress(uint32_t now) {
15 if (mNotStarted) {
16 return 0;
17 }
18 if (now < mStart) {
19 return 0;
20 } else if (now >= mStart + mDuration) {
21 return 255;
22 } else {
23 return ((now - mStart) * 255) / mDuration;
24 }
25 }
26
27 void start(uint32_t now, uint32_t duration) {
28 mNotStarted = false;
29 mStart = now;
30 mDuration = duration;
31 }
32
33 void end() {
34 mNotStarted = true;
35 }
36
37 bool isTransitioning(uint32_t now) {
38 if (mNotStarted) {
39 return false;
40 }
41 return now >= mStart && now < mStart + mDuration;
42 }
43
44private:
45 uint32_t mStart;
46 uint32_t mDuration;
47 bool mNotStarted;
48};
49
50
51FASTLED_NAMESPACE_END
52