code cleanup

- removed commented-out code
- reduced blank lines
This commit is contained in:
Frank
2024-07-16 20:48:15 +02:00
parent 7a83f1759d
commit 9bcc5da132
2 changed files with 12 additions and 57 deletions

View File

@@ -8388,13 +8388,15 @@ uint16_t mode_2Dwavingcell() {
}
static const char _data_FX_MODE_2DWAVINGCELL[] PROGMEM = "Waving Cell@!,,Amplitude 1,Amplitude 2,Amplitude 3;;!;2";
/////////////////////////
// ** 3D GEQ //
/////////////////////////
uint16_t mode_GEQLASER(void) {
// Author: @TroyHacks
const size_t dataSize = sizeof(uint16_t);
if (!SEGENV.allocateData(dataSize * 2)) return mode_static(); //allocation failed
uint16_t *projector = reinterpret_cast<uint16_t*>(SEGENV.data);
uint16_t *projector_dir = reinterpret_cast<uint16_t*>(SEGENV.data + dataSize);
@@ -8411,11 +8413,13 @@ uint16_t mode_GEQLASER(void) {
SEGMENT.fill(BLACK);
const int NUM_BANDS = map(SEGMENT.custom3, 0, 31, 1, 16); // custom3 is 0..31
uint32_t ledColorTemp;
const int cols = SEGMENT.virtualWidth();
const int rows = SEGMENT.virtualHeight();
uint32_t ledColorTemp;
uint_fast8_t split = map(*projector,0,SEGMENT.virtualWidth(),0,(NUM_BANDS - 1));
const int NUM_BANDS = map(SEGMENT.custom3, 0, 31, 1, 16); // custom3 is 0..31
uint_fast8_t split = map(*projector,0,SEGMENT.virtualWidth(),0,(NUM_BANDS - 1));
uint16_t horizon = map(SEGMENT.custom1,0,255,rows-1,0);
uint8_t depth = SEGMENT.custom2; // depth of perspective. 255 = infinite ("laser")
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
@@ -8429,108 +8433,78 @@ uint16_t mode_GEQLASER(void) {
heights[i] = map8(fftResult[i],0,rows*0.85); // cache fftResult[] as data might be updated in parallel by the audioreactive core
}
uint16_t horizon = map(SEGMENT.custom1,0,255,rows-1,0);
uint8_t depth = SEGMENT.custom2; // depth of perspective. 255 = infinite ("laser")
for (int i=0; i<=split; i++) { // paint right vertical faces and top - LEFT to RIGHT
uint16_t colorIndex = map(cols/NUM_BANDS*i, 0, cols-1, 0, 255);
uint32_t ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0);
int linex = i*(cols/NUM_BANDS);
if (heights[i] > 1) {
ledColorTemp = color_fade(ledColor,32,true);
int pPos = linex+(cols/NUM_BANDS)-1;
for (int y = (i<NUM_BANDS-1) ? heights[i+1] : 0; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
SEGMENT.drawLine(pPos,rows-y-1,*projector,horizon,ledColorTemp,false,depth); // right side perspective
}
ledColorTemp = color_fade(ledColor,128,true);
if (heights[i] < rows-horizon && (*projector <=linex || *projector >= pPos)) { // draw if above horizon AND not directly under projector (special case later)
for (uint_fast8_t x=linex; x<=pPos;x++) {
bool doSoft = SEGMENT.check2 && ((x==linex) || (x==pPos)); // only first and last line need AA
SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,doSoft,depth); // top perspective
}
}
}
}
for (int i=(NUM_BANDS - 1); i>split; i--) { // paint left vertical faces and top - RIGHT to LEFT
for (int i=(NUM_BANDS - 1); i>split; i--) { // paint left vertical faces and top - RIGHT to LEFT
uint16_t colorIndex = map(cols/NUM_BANDS*i, 0, cols-1, 0, 255);
uint32_t ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0);
int linex = i*(cols/NUM_BANDS);
int pPos = linex+(cols/NUM_BANDS)-1;
if (heights[i] > 1) {
ledColorTemp = color_fade(ledColor,32,true);
for (uint_fast8_t y = (i>0) ? heights[i-1] : 0; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
SEGMENT.drawLine(linex,rows-y-1,*projector,horizon,ledColorTemp,false,depth); // left side perspective
}
ledColorTemp = color_fade(ledColor,128,true);
if (heights[i] < rows-horizon && (*projector <=linex || *projector >= pPos)) { // draw if above horizon AND not directly under projector (special case later)
for (uint_fast8_t x=linex; x<=pPos;x++) {
bool doSoft = SEGMENT.check2 && ((x==linex) || (x==pPos)); // only first and last line need AA
SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,doSoft,depth); // top perspective
}
}
}
}
for (int i=0; i<NUM_BANDS; i++) {
for (int i=0; i<NUM_BANDS; i++) {
uint16_t colorIndex = map(cols/NUM_BANDS*i, 0, cols-1, 0, 255);
uint32_t ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0);
int linex = i*(cols/NUM_BANDS);
int pPos = linex+(cols/NUM_BANDS)-1;
int pPos1 = linex+(cols/NUM_BANDS);
if (*projector >=linex && *projector <= pPos) { // special case when top perspective is directly under the projector
if (heights[i] > 1 && heights[i] < rows-horizon) {
ledColorTemp = color_fade(ledColor,128,true);
for (uint_fast8_t x=linex; x<=pPos;x++) {
SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,false,depth); // top perspective
}
}
}
if (heights[i] > 1) {
ledColorTemp = color_fade(ledColor,SEGMENT.intensity,true);
for (uint_fast8_t x=linex; x<pPos1;x++) {
SEGMENT.drawLine(x,rows-1,x,rows-heights[i]-1,ledColorTemp); // front fill
}
if (!SEGMENT.check1 && heights[i] > rows-horizon) {
if (SEGMENT.intensity == 0) ledColorTemp = color_fade(ledColor,32,true); // match side fill if we're in blackout mode
SEGMENT.drawLine(linex,rows-heights[i]-1,linex+(cols/NUM_BANDS)-1,rows-heights[i]-1,ledColorTemp); // top line to simulate hidden top fill
}
if (SEGMENT.check1) {
@@ -8538,14 +8512,10 @@ uint16_t mode_GEQLASER(void) {
SEGMENT.drawLine(linex+(cols/NUM_BANDS)-1,rows-1,linex+(cols/NUM_BANDS)-1,rows-heights[i]-1,ledColor); // right side line
SEGMENT.drawLine(linex, rows-heights[i]-2,linex+(cols/NUM_BANDS)-1,rows-heights[i]-2,ledColor); // top line
SEGMENT.drawLine(linex, rows-1,linex+(cols/NUM_BANDS)-1,rows-1,ledColor); // bottom line
}
}
}
}
return FRAMETIME;
}
static const char _data_FX_MODE_GEQLASER[] PROGMEM = "GEQ 3D ☾@Speed,Front Fill,Horizon,Depth,Num Bands,Borders,Soft,;!,,Peaks;!;2f;sx=255,ix=255,c1=255,c2=255,c3=255,pal=11";