-
Notifications
You must be signed in to change notification settings - Fork 7
/
curtain.cpp
75 lines (61 loc) · 1.84 KB
/
curtain.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
#include "curtain.h"
#include <Assert.h>
#include <Logging.h>
#include <Math.h>
using namespace pixl;
CurtainAnimation::CurtainAnimation(Visualization* viz, LEDs& leds)
: leds_(leds),
viz_(viz)
{ }
CurtainAnimation::~CurtainAnimation() {
delete[] mapping_;
}
void CurtainAnimation::init() {}
void CurtainAnimation::init(int height_px, int width_px,
double height_r, double width_r,
double rotation_rad,
double x_r, double y_r, double z_r)
{
Log.Info("Setting up Curtain animation\n");
assert( (height_px * width_px) <= leds_.length() );
mapping_ = new double[leds_.length()];
for (int i = 0; i < leds_.length(); i++) {
mapping_[i] = 0.0;
}
// Assumes LEDs start at the top right corner and then go down, left, back
// up, left back down, etc.
int x = width_px - 1;
int y = 0;
int y_inc = 1;
for (int i = 0; i < leds_.length(); i++) {
// Find distance from top left corner (0,0)
double x_distance = width_r * ((double)(x + 1) / (double)width_px);
double y_distance = height_r * ((double)(y + 1) / (double)height_px);
// Find distance from start of visualization
x_distance += x_r;
y_distance += y_r;
double distance = sqrt( pow(x_distance, 2) + pow(y_distance, 2) );
// Verify it's between 0 and 1
distance = max(0.0, distance);
distance = min(1.0, distance);
// Add the mapping
mapping_[i] = distance;
// Calculate new x,y coordinates
y += y_inc;
if (y == height_px) {
x--;
y = height_px - 1;
y_inc = -1;
} else if (y < 0) {
x--;
y = 0;
y_inc = 1;
}
}
}
void CurtainAnimation::update() {}
void CurtainAnimation::draw(float interpolation) {
for (int i = 0; i < leds_.length(); i++) {
leds_[i] = viz_->getColorByRatio(mapping_[i]);
}
}