92 lines
2.2 KiB
C++
92 lines
2.2 KiB
C++
#include "corner.h"
|
|
#include "prototypes.h"
|
|
#include "tools.h"
|
|
|
|
Corner::Corner(Edge* new_e1, Edge* new_e2): e1(new_e1), e2(new_e2) {
|
|
|
|
}
|
|
|
|
void Corner::draw() {
|
|
for(uint16_t led: this->_leds) {
|
|
leds[led] = this->color;
|
|
}
|
|
}
|
|
|
|
void Corner::infect(std::vector<Corner*>* neighbours) {
|
|
for(Corner* c : *neighbours) {
|
|
if (c==nullptr) continue;
|
|
c->blend_to(this->target_color, this->effect_id);
|
|
}
|
|
}
|
|
|
|
bool Corner::loop() {
|
|
if (this->color_blend_state < 255) {
|
|
this->color = blend(this->source_color, this->target_color, color_blend_state);
|
|
color_blend_state++;
|
|
|
|
if (color_blend_state == 200) {
|
|
infect(&_long_neighbours);
|
|
}
|
|
|
|
if (color_blend_state==75) {
|
|
infect(&_short_neighbours);
|
|
}
|
|
|
|
if (color_blend_state==255) {
|
|
this->color = this->target_color;
|
|
}
|
|
/* LOGln("I am %p and have %d long neighbours:", this, _long_neighbours.size());
|
|
for(Corner* c1 : _long_neighbours) {
|
|
if (c1==nullptr) continue;
|
|
c1->blend_to(this->target_color, this->effect_id);
|
|
|
|
LOGln("c1: cbs:%d, target_color.r:%d", c1->color_blend_state, c1->target_color.r);
|
|
}
|
|
LOGln("long neighbours done.");
|
|
//LOGln("Address of my short neighbours: %p", &_short_neighbours);
|
|
//delay(10);
|
|
LOGln("I am %p and have %d short neighbours:", this, _short_neighbours.size());
|
|
for(Corner* c2 : _short_neighbours) {
|
|
if (c2==nullptr) continue;
|
|
LOGln("c2: %p", c2);
|
|
c2->blend_to(this->target_color, this->effect_id);
|
|
|
|
LOGln("c2: cbs:%d, target_color.r:%d", c2->color_blend_state, c2->target_color.r);
|
|
}
|
|
LOGln("short neighbours done.");
|
|
|
|
}*/
|
|
}
|
|
|
|
this->draw();
|
|
|
|
return color_blend_state < 255;
|
|
}
|
|
|
|
void Corner::blend_to(CRGB target, uint16_t eid) {
|
|
LOGln("blendTo called. Corner: %p, target: %d,%d,%d, eid: %d, 'old' effect_id: %d", this, target.r, target.g, target.b, eid, effect_id);
|
|
if (eid==0) {
|
|
this->effect_id = random16();
|
|
LOGln("Set effect_id to %d", this->effect_id);
|
|
} else {
|
|
if (this->effect_id == eid) {
|
|
LOGln("'Old' effect. Doing nothing.");
|
|
return;
|
|
}
|
|
this->effect_id = eid;
|
|
}
|
|
|
|
this->source_color = this->color;
|
|
this->target_color = target;
|
|
this->color_blend_state = 0;
|
|
}
|
|
|
|
void Corner::add_led(uint16_t led) {
|
|
_leds.push_back(led);
|
|
}
|
|
|
|
void Corner::merge_leds(Corner* c) {
|
|
for(uint16_t led : c->_leds) {
|
|
_leds.push_back(led);
|
|
}
|
|
} |