@@ -5137,6 +5137,7 @@ static const char _data_FX_MODE_2DDNASPIRAL[] PROGMEM = "DNA Spiral@Scroll speed
51375137// 2D Drift //
51385138// ///////////////////////
51395139uint16_t mode_2DDrift () { // By: Stepko https://editor.soulmatelights.com/gallery/884-drift , Modified by: Andrew Tuline
5140+ // optimized for large panels by @softhack007
51405141 if (!strip.isMatrix ) return mode_static (); // not a 2D set-up
51415142
51425143 const uint16_t cols = SEGMENT.virtualWidth ();
@@ -5147,22 +5148,40 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli
51475148 SEGMENT.fill (BLACK);
51485149 }
51495150
5150- SEGMENT.fadeToBlackBy (128 );
5151+ if (SEGMENT.intensity > 1 ) SEGMENT.fadeToBlackBy (128 );
5152+ else SEGMENT.fill (BLACK); // WLEDMM fill is faster than fade
5153+ const float maxDim = max (cols, rows)/2 .0f ;
51515154
5152- const uint16_t maxDim = MAX (cols, rows)/2 ;
5153- unsigned long t = strip.now / (32 - (SEGMENT.speed >>3 ));
5154- unsigned long t_20 = t/20 ; // softhack007: pre-calculating this gives about 10% speedup
5155- for (float i = 1 ; i < maxDim; i += 0.25 ) {
5156- float angle = radians (t * (maxDim - i));
5157- uint16_t myX = (cols>>1 ) + (uint16_t )(sinf (angle) * i) + (cols%2 );
5158- uint16_t myY = (rows>>1 ) + (uint16_t )(cosf (angle) * i) + (rows%2 );
5159- SEGMENT.setPixelColorXY (myX, myY, ColorFromPalette (SEGPALETTE, (i * 20 ) + t_20, 255 , LINEARBLEND));
5160- }
5161- SEGMENT.blur (SEGMENT.intensity >>3 );
5155+ // WLEDMM calculate timebase in float, so we don't need to worry about rounding
5156+ const float strip_now = strip.now & 0x003FFFFF ; // float can exactly represent numbers up to 22bit
5157+ float t;
5158+ if (maxDim < 6 .0f ) t = strip_now / float (16U - (SEGMENT.speed >>4 )); // up to 12 (faster)
5159+ else if (maxDim <= 16 .0f ) t = strip_now / float (32U - (SEGMENT.speed >>3 )); // 12..32 (standard)
5160+ else if (maxDim <= 32 .0f ) t = strip_now / float (64U - (SEGMENT.speed >>2 )); // 32..64 (slower)
5161+ else t = strip_now / float (256U - SEGMENT.speed ); // above 64 (slowest)
5162+
5163+ // WLEDMM pre-calculate some values to speed up the main loop
5164+ const int colsCenter = (cols >> 1 ) + (cols % 2 );
5165+ const int rowsCenter = (rows >> 1 ) + (rows % 2 );
5166+ unsigned t_20 = t/20 .0f ; // softhack007: pre-calculating this gives about 10% speedup
5167+ const float step = (maxDim < 6 .0f ) ? 0 .52f : (maxDim > 24 .0f ) ? 0 .16666666f : 0 .25f ; // WLEDMM more detail on larger panels
51625168
5169+ for (float i = 1 .0f ; i <= maxDim; i += step) {
5170+ unsigned i_20 = i * 20 .0f ;
5171+ float t_maxdim = t * (maxDim - i);
5172+ float angle = float (DEG_TO_RAD) * t_maxdim;
5173+ int mySin = sinf (angle) * i;
5174+ int myCos = cosf (angle) * i;
5175+
5176+ if ((unsigned (colsCenter+mySin) < cols) && (unsigned (rowsCenter+myCos) < rows)) // don't draw invisible pixels
5177+ SEGMENT.setPixelColorXY (colsCenter+mySin, rowsCenter+myCos, ColorFromPalette (SEGPALETTE, i_20 + t_20, 255 , LINEARBLEND));
5178+ if ((SEGMENT.check1 ) && (unsigned (colsCenter+myCos) < cols) && (unsigned (rowsCenter+mySin) < rows))
5179+ SEGMENT.setPixelColorXY (colsCenter+myCos, rowsCenter+mySin, ColorFromPalette (SEGPALETTE, i_20 + t_20, 255 , LINEARBLEND)); // twin mode
5180+ }
5181+ SEGMENT.blur (SEGMENT.intensity >>((!SEGMENT.check2 ) * 3 ), SEGMENT.check2 ); // user-defined blur - thanks @dedehai
51635182 return FRAMETIME;
51645183} // mode_2DDrift()
5165- static const char _data_FX_MODE_2DDRIFT[] PROGMEM = " Drift@Rotation speed,Blur amount ;;!;2" ;
5184+ static const char _data_FX_MODE_2DDRIFT[] PROGMEM = " Drift@Rotation speed,Blur,,,,Twin,Smear ;;!;2;ix=0 " ;
51665185
51675186
51685187// ////////////////////////
0 commit comments