-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition_animate_waves.cpp
85 lines (69 loc) · 2.85 KB
/
transition_animate_waves.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
82
#include "core/properties.hpp"
#include "transition_animate.hpp"
#include "types.hpp"
#include "utility_colorwheel.hpp"
namespace sc {
static void cyclicIncrement( double& value, double increment )
{
value += increment;
while ( value > 1.0 ) {
value -= 1.0;
}
}
static void cyclicDecrement( double& value, double decrement )
{
value -= decrement;
while ( value < 0.0 ) {
value += 1.0;
}
}
struct WaveAnimationData
{
double brightnessOffset {};
double colorOffset {};
};
static PropertyKey colorRangeProperty( "colorRange", 1.0 );
static PropertyKey colorSpeedProperty( "colorSpeed" );
static PropertyKey pulseRangeProperty( "pulseRange", 1.0 );
static PropertyKey pulseSpeedProperty( "pulseSpeed" );
static PropertyKey minBrightProperty( "minBright" );
static PropertyKey maxBrightProperty( "maxBright" );
class TransitionAnimateWaves
: public AnimateTransition< WaveAnimationData >
{
public:
TransitionAnimateWaves( std::string&& id, Manager& manager, PropertyNode const& properties )
: AnimateTransition< WaveAnimationData >( move( id ), manager )
, colorRange_( properties[ colorRangeProperty ].as< double >() )
, colorSpeed_( properties[ colorSpeedProperty ].as< double >() )
, pulseRange_( properties[ pulseRangeProperty ].as< double >() )
, pulseSpeed_( properties[ pulseSpeedProperty ].as< double >() )
, minBright_( properties[ minBrightProperty ].as< double >() )
, maxBright_( properties[ maxBrightProperty ].as< double >() )
{
}
protected:
void animate( ChannelBuffer& output, WaveAnimationData& data, double elapsed ) const override
{
ColorBuffer colorBuffer( output );
auto brightnessIndex = data.brightnessOffset;
auto colorIndex = data.colorOffset;
for ( auto pixel : colorBuffer ) {
auto brightness = sin( brightnessIndex * 6.283 ) * ( maxBright_ - minBright_ ) + minBright_;
pixel = Colorwheel< 256 >::get( colorIndex * 255.0 ).scale( brightness );
cyclicIncrement( brightnessIndex, pulseRange_ / colorBuffer.size() );
cyclicIncrement( colorIndex, colorRange_ / colorBuffer.size() );
}
cyclicDecrement( data.brightnessOffset, pulseSpeed_ * elapsed );
cyclicIncrement( data.colorOffset, colorSpeed_ * elapsed );
}
private:
double colorRange_;
double colorSpeed_;
double pulseRange_;
double pulseSpeed_;
double minBright_;
double maxBright_;
};
static TransitionRegistry< TransitionAnimateWaves > registry( "animate:waves" );
} // namespace sc