forked from sowbug/G35Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orbiter.cpp
47 lines (38 loc) · 1.08 KB
/
Orbiter.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
/*
G35: An Arduino library for GE Color Effects G-35 holiday lights.
Copyright © 2011 The G35 Authors. Use, modification, and distribution are
subject to the BSD license as described in the accompanying LICENSE file.
By Mike Tsao <http://github.com/sowbug>.
See README for complete attributions.
*/
#include <Orbiter.h>
Orbiter::Orbiter()
: radius_((float)rand() / (float)RAND_MAX),
angle_(2 * PI * (float)rand() / (float)RAND_MAX),
d_angle_(0),
x_(0),
color_(G35::max_color(rand())) {
const float MIN_ACTION = 0.005;
while (d_angle_ < MIN_ACTION && d_angle_ > -MIN_ACTION) {
d_angle_ = -0.02 + 0.04 * (float)rand() / (float)RAND_MAX;
}
}
Orbiter::Orbiter(float radius, float d_angle)
: radius_(radius),
angle_(0),
d_angle_(d_angle),
x_(0),
color_(G35::max_color(rand())) {}
void Orbiter::Do() {
x_ = sin(angle_) * radius_;
angle_ += d_angle_;
}
float Orbiter::x() {
return x_;
}
uint8_t Orbiter::x_local(uint8_t range, uint8_t center) {
return ((uint8_t)(x_ * range + center)) % range;
}
color_t Orbiter::color() {
return color_;
}