Skip to content

Commit

Permalink
BugFix Octopus out of bounds in projections
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Jun 24, 2024
1 parent 49a9fe3 commit 09752af
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,11 @@ class Octopus: public Effect {
const uint8_t C_Y = leds.size.y / 2 + (offsetY - 128)*leds.size.y/255;
for (pos.x = 0; pos.x < leds.size.x; pos.x++) {
for (pos.y = 0; pos.y < leds.size.y; pos.y++) {
rMap[leds.XY(pos.x, pos.y)].angle = 40.7436f * atan2f(pos.y - C_Y, pos.x - C_X); // avoid 128*atan2()/PI
rMap[leds.XY(pos.x, pos.y)].radius = hypotf(pos.x - C_X, pos.y - C_Y) * mapp; //thanks Sutaburosu
uint16_t indexV = leds.XY(pos.x, pos.y);
if (indexV < leds.size.x * leds.size.y) { //excluding UINT16_MAX from XY if out of bounds due to projection
rMap[indexV].angle = 40.7436f * atan2f(pos.y - C_Y, pos.x - C_X); // avoid 128*atan2()/PI
rMap[indexV].radius = hypotf(pos.x - C_X, pos.y - C_Y) * mapp; //thanks Sutaburosu
}
}
}
}
Expand All @@ -1200,13 +1203,16 @@ class Octopus: public Effect {

for (pos.x = 0; pos.x < leds.size.x; pos.x++) {
for (pos.y = 0; pos.y < leds.size.y; pos.y++) {
byte angle = rMap[leds.XY(pos.x,pos.y)].angle;
byte radius = rMap[leds.XY(pos.x,pos.y)].radius;
//CRGB c = CHSV(*step / 2 - radius, 255, sin8(sin8((angle * 4 - radius) / 4 + *step) + radius - *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, UINT16_MAX, 0, 255); // add a bit of non-linearity for cleaner display
CRGB color = ColorFromPalette(leds.palette, *step / 2 - radius, intensity);
leds[pos] = color;
uint16_t indexV = leds.XY(pos.x, pos.y);
if (indexV < leds.size.x * leds.size.y) { //excluding UINT16_MAX from XY if out of bounds due to projection
byte angle = rMap[indexV].angle;
byte radius = rMap[indexV].radius;
//CRGB c = CHSV(*step / 2 - radius, 255, sin8(sin8((angle * 4 - radius) / 4 + *step) + radius - *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, UINT16_MAX, 0, 255); // add a bit of non-linearity for cleaner display
CRGB color = ColorFromPalette(leds.palette, *step / 2 - radius, intensity);
leds[pos] = color;
}
}
}
}
Expand Down

0 comments on commit 09752af

Please sign in to comment.