-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfade_effect.cpp
51 lines (46 loc) · 1004 Bytes
/
fade_effect.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
#include "fade_effect.h"
unsigned int FadeEffect::maxDelay()
{
return -1;
}
void FadeEffect::init()
{
// Handle a corner case in which the update just increments
// a color and overflows the byte
if( R() == 255 ) R(254);
if( G() == 255 ) G(254);
if( B() == 255 ) R(254);
if( R() == 0 ) R(1);
if( G() == 0 ) G(1);
if( B() == 0 ) R(1);
stage = 0;
renderTime = 0;
}
void FadeEffect::update()
{
if( millis() < renderTime ) return;
switch(stage)
{
case 0:
if( G( G()+1 ) == 255 ) ++stage;
break;
case 1:
if( R( R()-1 ) == 0 ) ++stage;
break;
case 2:
if( B( B()+1 ) == 255 ) ++stage;
break;
case 3:
if( G( G()-1 ) == 0 ) ++stage;
break;
case 4:
if( R( R()+1 ) == 255 ) ++stage;
break;
case 5:
if( B( B()-1 ) == 0 ) ++stage;
break;
}
if( stage == 6 )
stage = 0;
renderTime += ceil((float)m_duration / 1536);
}