-
Notifications
You must be signed in to change notification settings - Fork 24
/
Orbit.cpp
51 lines (42 loc) · 1.21 KB
/
Orbit.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
/*
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 <Orbit.h>
Orbit::Orbit(G35& g35)
: LightProgram(g35),
should_erase_(true),
count_(MAX_OBJECTS),
light_count_(g35_.get_light_count()) {
set_centers();
}
uint32_t Orbit::Do() {
for (int i = 0; i < count_; ++i) {
Orbiter *o = &orbiter_[i];
o->Do();
uint8_t x = o->x_local(light_count_, orbiter_center_[i]);
if (should_erase_ && last_x_[i] != x) {
g35_.set_color(last_x_[i], 255, COLOR_BLACK);
last_x_[i] = x;
}
g35_.set_color(x, 255, o->color());
}
return bulb_frame_ >> 1;
}
Orbit::Orbit(G35& g35, bool should_erase)
: LightProgram(g35),
should_erase_(should_erase),
count_(MAX_OBJECTS),
light_count_(g35_.get_light_count()) {
set_centers();
}
void Orbit::set_centers() {
for (int i = 0; i < count_; ++i) {
orbiter_center_[i] = rand() % light_count_;
last_x_[i] = 0;
}
}
OrbitSmudge::OrbitSmudge(G35& g35) : Orbit(g35, false) {}