-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcircle.cpp
51 lines (39 loc) · 1.3 KB
/
circle.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
#include "circle.h"
#include <Logging.h>
using namespace pixl;
CircleAnimation::CircleAnimation(Visualization* viz, LEDs** leds, int num_leds)
: leds_(leds),
num_leds_(num_leds),
viz_(viz) {}
CircleAnimation::~CircleAnimation() {
delete[] mapping_;
}
void CircleAnimation::init() {}
void CircleAnimation::init(float scale) {
Log.Info("Setting up Circle animation\n");
int length = leds_[0]->length();
mapping_ = new float[length];
float radius = (float)length / (2.0 * 3.1415);
Log.Debug("Radius: %d (x1000)\n", (int)(radius * 1000.0));
float viz_scaled = viz_->getSize() * scale;
for (int i = 0; i < length; i++) {
float radians = ((float)i / ((float)length - 1.0)) * (2.0 * 3.1415);
float a = sin(radians) * radius;
float b = cos(radians) * radius;
float y = radius - b;
float x = sqrt(a * a + y * y);
float map = x / viz_scaled;
mapping_[i] = x / viz_scaled;
Log.Debug("Mapping of %d: %d (x1000)\n", i, (int)(map * 1000.0));
}
Log.Info("Finished setting up Circle animation\n");
}
void CircleAnimation::update() {}
void CircleAnimation::draw(float interpolation) {
for (int i = 0; i < num_leds_; i++) {
LEDs* leds = leds_[i];
for (int j = 0; j < leds->length(); j++) {
(*leds)[j] = viz_->getColorByRatio(mapping_[j]);
}
}
}