@@ -7407,7 +7407,7 @@ static const char _data_FX_MODE_2DAKEMI[] PROGMEM = "Akemi@Color speed,Dance;Hea
74077407
74087408// Distortion waves - ldirko
74097409// https://editor.soulmatelights.com/gallery/1089-distorsion-waves
7410- // adapted for WLED by @blazoncek
7410+ // adapted for WLED by @blazoncek, improvements by @dedehai
74117411uint16_t mode_2Ddistortionwaves () {
74127412 if (!strip.isMatrix || !SEGMENT.is2D ()) return mode_static (); // not a 2D set-up
74137413
@@ -7416,20 +7416,23 @@ uint16_t mode_2Ddistortionwaves() {
74167416
74177417 uint8_t speed = SEGMENT.speed /32 ;
74187418 uint8_t scale = SEGMENT.intensity /32 ;
7419-
7420- uint8_t w = 2 ;
7419+ if (SEGMENT.check2 ) scale += 192 / (cols+rows); // zoom out some more. note: not changing scale slider for backwards compatibility
74217420
74227421 unsigned a = strip.now /32 ;
74237422 unsigned a2 = a/2 ;
74247423 unsigned a3 = a/3 ;
7424+ unsigned colsScaled = cols * scale;
7425+ unsigned rowsScaled = rows * scale;
7426+
7427+ unsigned cx = beatsin16_t (10 -speed,0 ,colsScaled);
7428+ unsigned cy = beatsin16_t (12 -speed,0 ,rowsScaled);
7429+ unsigned cx1 = beatsin16_t (13 -speed,0 ,colsScaled);
7430+ unsigned cy1 = beatsin16_t (15 -speed,0 ,rowsScaled);
7431+ unsigned cx2 = beatsin16_t (17 -speed,0 ,colsScaled);
7432+ unsigned cy2 = beatsin16_t (14 -speed,0 ,rowsScaled);
7433+
7434+ byte rdistort, gdistort, bdistort;
74257435
7426- unsigned cx = beatsin8_t (10 -speed,0 ,cols-1 )*scale;
7427- unsigned cy = beatsin8_t (12 -speed,0 ,rows-1 )*scale;
7428- unsigned cx1 = beatsin8_t (13 -speed,0 ,cols-1 )*scale;
7429- unsigned cy1 = beatsin8_t (15 -speed,0 ,rows-1 )*scale;
7430- unsigned cx2 = beatsin8_t (17 -speed,0 ,cols-1 )*scale;
7431- unsigned cy2 = beatsin8_t (14 -speed,0 ,rows-1 )*scale;
7432-
74337436 unsigned xoffs = 0 ;
74347437 for (int x = 0 ; x < cols; x++) {
74357438 xoffs += scale;
@@ -7438,25 +7441,49 @@ uint16_t mode_2Ddistortionwaves() {
74387441 for (int y = 0 ; y < rows; y++) {
74397442 yoffs += scale;
74407443
7441- byte rdistort = cos8_t ((cos8_t (((x<<3 )+a )&255 )+cos8_t (((y<<3 )-a2)&255 )+a3 )&255 )>>1 ;
7442- byte gdistort = cos8_t ((cos8_t (((x<<3 )-a2)&255 )+cos8_t (((y<<3 )+a3)&255 )+a+32 )&255 )>>1 ;
7443- byte bdistort = cos8_t ((cos8_t (((x<<3 )+a3)&255 )+cos8_t (((y<<3 )-a) &255 )+a2+64 )&255 )>>1 ;
7444+ if (SEGMENT.check3 ) {
7445+ // alternate mode from original code
7446+ rdistort = cos8_t (((x+y)*8 +a2)&255 )>>1 ;
7447+ gdistort = cos8_t (((x+y)*8 +a3+32 )&255 )>>1 ;
7448+ bdistort = cos8_t (((x+y)*8 +a+64 )&255 )>>1 ;
7449+ } else {
7450+ rdistort = cos8_t ((cos8_t (((x<<3 )+a )&255 )+cos8_t (((y<<3 )-a2)&255 )+a3 )&255 )>>1 ;
7451+ gdistort = cos8_t ((cos8_t (((x<<3 )-a2)&255 )+cos8_t (((y<<3 )+a3)&255 )+a+32 )&255 )>>1 ;
7452+ bdistort = cos8_t ((cos8_t (((x<<3 )+a3)&255 )+cos8_t (((y<<3 )-a) &255 )+a2+64 )&255 )>>1 ;
7453+ }
74447454
7445- byte valueR = rdistort+ w* ( a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ));
7446- byte valueG = gdistort+ w* ( a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ));
7447- byte valueB = bdistort+ w* ( a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ));
7455+ byte valueR = rdistort + (( a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ))<< 1 );
7456+ byte valueG = gdistort + (( a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ))<< 1 );
7457+ byte valueB = bdistort + (( a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ))<< 1 );
74487458
74497459 valueR = gamma8 (cos8_t (valueR));
74507460 valueG = gamma8 (cos8_t (valueG));
74517461 valueB = gamma8 (cos8_t (valueB));
74527462
7453- SEGMENT.setPixelColorXY (x, y, RGBW32 (valueR, valueG, valueB, 0 ));
7463+ if (SEGMENT.palette == 0 ) {
7464+ // use RGB values (original color mode)
7465+ SEGMENT.setPixelColorXY (x, y, RGBW32 (valueR, valueG, valueB, 0 ));
7466+ } else {
7467+ // use palette
7468+ uint8_t brightness = (valueR + valueG + valueB) / 3 ;
7469+ if (SEGMENT.check1 ) { // map brightness to palette index
7470+ SEGMENT.setPixelColorXY (x, y, ColorFromPalette (SEGPALETTE, brightness, 255 , LINEARBLEND_NOWRAP));
7471+ } else {
7472+ // color mapping: calculate hue from pixel color, map it to palette index
7473+ CHSV hsvclr = rgb2hsv_approximate (CRGB (valueR>>2 , valueG>>2 , valueB>>2 )); // scale colors down to not saturate for better hue extraction
7474+ SEGMENT.setPixelColorXY (x, y, ColorFromPalette (SEGPALETTE, hsvclr.h , brightness));
7475+ }
7476+ }
74547477 }
74557478 }
74567479
7480+ // palette mode and not filling: smear-blur to cover up palette wrapping artefacts
7481+ if (!SEGMENT.check1 && SEGMENT.palette )
7482+ SEGMENT.blur (200 , true );
7483+
74577484 return FRAMETIME;
74587485}
7459- static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = " Distortion Waves@!,Scale;;;2 " ;
7486+ static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = " Distortion Waves@!,Scale,,,,Fill,Zoom,Alt;;!;2;pal=0 " ;
74607487
74617488
74627489// Soap
0 commit comments