Skip to content

Commit

Permalink
Add effect blending (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewowi committed Feb 18, 2024
1 parent bc35ad5 commit 877de68
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class Octopus2D: public Effect {
byte radius = rMap[leds.XY(pos.x,pos.y)].radius;
//CRGB c = CHSV(SEGENV.step / 2 - radius, 255, sin8(sin8((angle * 4 - radius) / 4 + SEGENV.step) + radius - SEGENV.step * 2 + angle * (SEGMENT.custom3/3+1)));
uint16_t intensity = sin8(sin8((angle * 4 - radius) / 4 + *step/2) + radius - *step + angle * legs);
intensity = map(intensity*intensity, 0, 65535, 0, 255); // add a bit of non-linearity for cleaner display
intensity = map(intensity*intensity, 0, UINT16_MAX, 0, 255); // add a bit of non-linearity for cleaner display
CRGB color = ColorFromPalette(pal, *step / 2 - radius, intensity);
leds[pos] = color;
}
Expand Down
7 changes: 5 additions & 2 deletions src/App/AppFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ class Fixture {
//track pins and leds

bool doMap = false;

uint8_t globalBlend = 128;

//load fixture json file, parse it and depending on the projection, create a mapping for it
void projectAndMap();

float distance(uint16_t x1, uint16_t y1, uint16_t z1, uint16_t x2, uint16_t y2, uint16_t z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
return distance(Coord3D{x1, y1, z1}, Coord3D{x2,y2,z2});
// return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}
float distance(Coord3D c1, Coord3D c2) {
Coord3D delta = c1-c2;
Coord3D delta = (c1-c2).absx();
return sqrtf((delta.x)*(delta.x) + (delta.y)*(delta.y) + (delta.z)*(delta.z));
}

Expand Down
8 changes: 4 additions & 4 deletions src/App/AppLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Leds::setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount) {
}
else {
for (uint16_t indexP:mappingTable[indexV]) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount);
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ void Leds::fadeToBlackBy(uint8_t fadeBy) {
for (uint16_t indexP:*physMap) {
CRGB oldValue = fixture->ledsP[indexP];
fixture->ledsP[indexP].nscale8(255-fadeBy); //this overrides the old value
fixture->ledsP[indexP] = blend(fixture->ledsP[indexP], oldValue, 128); // we want to blend in the old value
fixture->ledsP[indexP] = blend(fixture->ledsP[indexP], oldValue, fixture->globalBlend); // we want to blend in the old value
}
}
}
Expand All @@ -68,7 +68,7 @@ void Leds::fill_solid(const struct CRGB& color) {
//fade2black for old start to endpos
for (std::vector<std::vector<uint16_t>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], 128);
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
}
}
Expand All @@ -81,7 +81,7 @@ void Leds::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {

for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], 128);
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
hsv.hue += deltahue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/App/AppLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class Leds {


// maps the virtual led to the physical led(s) and assign a color to it
void setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount = 128);
void setPixelColor(Coord3D pixel, CRGB color, uint8_t blendAmount = 128) {setPixelColor(XYZ(pixel), color, blendAmount);}
void setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount = UINT8_MAX);
void setPixelColor(Coord3D pixel, CRGB color, uint8_t blendAmount = UINT8_MAX) {setPixelColor(XYZ(pixel), color, blendAmount);}

CRGB getPixelColor(uint16_t indexV);
CRGB getPixelColor(Coord3D pixel) {return getPixelColor(XYZ(pixel));}
Expand Down
7 changes: 7 additions & 0 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ class AppModLeds:public SysModule {
default: return false;
}}); //fixtureGen

ui->initSlider(parentVar, "Blending", fixture.globalBlend, 0, 255, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_ChangeFun:
fixture.globalBlend = var["value"];
return true;
default: return false;
}});

#ifdef STARMOD_USERMOD_E131
// if (e131mod->isEnabled) {
e131mod->patchChannel(0, "bri", 255); //should be 256??
Expand Down

0 comments on commit 877de68

Please sign in to comment.