@@ -8645,7 +8645,7 @@ static const char _data_FX_MODE_2DAKEMI[] PROGMEM = "Akemi@Color speed,Dance;Hea
86458645
86468646// Distortion waves - ldirko
86478647// https://editor.soulmatelights.com/gallery/1089-distorsion-waves
8648- // adapted for WLED by @blazoncek
8648+ // adapted for WLED by @blazoncek, improvements by @dedehai
86498649uint16_t mode_2Ddistortionwaves() {
86508650 if (!strip.isMatrix) return mode_oops(); // not a 2D set-up
86518651
@@ -8654,47 +8654,74 @@ uint16_t mode_2Ddistortionwaves() {
86548654
86558655 uint8_t speed = SEGMENT.speed/32;
86568656 uint8_t scale = SEGMENT.intensity/32;
8657+ if(SEGMENT.check2) scale += 192 / (cols+rows); // zoom out some more. note: not changing scale slider for backwards compatibility
86578658
8658- uint8_t w = 2;
8659+ unsigned a = strip.now/32;
8660+ unsigned a2 = a/2;
8661+ unsigned a3 = a/3;
8662+ unsigned colsScaled = cols * scale;
8663+ unsigned rowsScaled = rows * scale;
86598664
8660- uint16_t a = strip.now/32;
8661- uint16_t a2 = a/2;
8662- uint16_t a3 = a/3;
8665+ unsigned cx = beatsin16_t(10-speed,0,colsScaled);
8666+ unsigned cy = beatsin16_t(12-speed,0,rowsScaled);
8667+ unsigned cx1 = beatsin16_t(13-speed,0,colsScaled);
8668+ unsigned cy1 = beatsin16_t(15-speed,0,rowsScaled);
8669+ unsigned cx2 = beatsin16_t(17-speed,0,colsScaled);
8670+ unsigned cy2 = beatsin16_t(14-speed,0,rowsScaled);
86638671
8664- uint16_t cx = beatsin8_t(10-speed,0,cols-1)*scale;
8665- uint16_t cy = beatsin8_t(12-speed,0,rows-1)*scale;
8666- uint16_t cx1 = beatsin8_t(13-speed,0,cols-1)*scale;
8667- uint16_t cy1 = beatsin8_t(15-speed,0,rows-1)*scale;
8668- uint16_t cx2 = beatsin8_t(17-speed,0,cols-1)*scale;
8669- uint16_t cy2 = beatsin8_t(14-speed,0,rows-1)*scale;
8670-
8671- uint16_t xoffs = 0;
8672+ byte rdistort, gdistort, bdistort;
8673+
8674+ unsigned xoffs = 0;
86728675 for (int x = 0; x < cols; x++) {
86738676 xoffs += scale;
86748677 uint16_t yoffs = 0;
86758678
86768679 for (int y = 0; y < rows; y++) {
86778680 yoffs += scale;
86788681
8679- byte rdistort = cos8_t((cos8_t(((x<<3)+a )&255)+cos8_t(((y<<3)-a2)&255)+a3 )&255)>>1;
8680- byte gdistort = cos8_t((cos8_t(((x<<3)-a2)&255)+cos8_t(((y<<3)+a3)&255)+a+32 )&255)>>1;
8681- byte bdistort = cos8_t((cos8_t(((x<<3)+a3)&255)+cos8_t(((y<<3)-a) &255)+a2+64)&255)>>1;
8682+ if(SEGMENT.check3) {
8683+ // alternate mode from original code
8684+ rdistort = cos8_t (((x+y)*8+a2)&255)>>1;
8685+ gdistort = cos8_t (((x+y)*8+a3+32)&255)>>1;
8686+ bdistort = cos8_t (((x+y)*8+a+64)&255)>>1;
8687+ } else {
8688+ rdistort = cos8_t((cos8_t(((x<<3)+a )&255)+cos8_t(((y<<3)-a2)&255)+a3 )&255)>>1;
8689+ gdistort = cos8_t((cos8_t(((x<<3)-a2)&255)+cos8_t(((y<<3)+a3)&255)+a+32 )&255)>>1;
8690+ bdistort = cos8_t((cos8_t(((x<<3)+a3)&255)+cos8_t(((y<<3)-a) &255)+a2+64)&255)>>1;
8691+ }
86828692
8683- byte valueR = rdistort+ w* ( a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ));
8684- byte valueG = gdistort+ w* ( a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ));
8685- byte valueB = bdistort+ w* ( a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ));
8693+ byte valueR = rdistort + (( a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ))<<1 );
8694+ byte valueG = gdistort + (( a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ))<<1 );
8695+ byte valueB = bdistort + (( a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ))<<1 );
86868696
86878697 valueR = gamma8(cos8_t(valueR));
86888698 valueG = gamma8(cos8_t(valueG));
86898699 valueB = gamma8(cos8_t(valueB));
86908700
8691- SEGMENT.setPixelColorXY(x, y, RGBW32(valueR, valueG, valueB, 0));
8701+ if(SEGMENT.palette == 0) {
8702+ // use RGB values (original color mode)
8703+ SEGMENT.setPixelColorXY(x, y, RGBW32(valueR, valueG, valueB, 0));
8704+ } else {
8705+ // use palette
8706+ uint8_t brightness = (valueR + valueG + valueB) / 3;
8707+ if(SEGMENT.check1) { // map brightness to palette index
8708+ SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, brightness, 255, LINEARBLEND_NOWRAP));
8709+ } else {
8710+ // color mapping: calculate hue from pixel color, map it to palette index
8711+ CHSV hsvclr = rgb2hsv_approximate(CRGB(valueR>>2, valueG>>2, valueB>>2)); // scale colors down to not saturate for better hue extraction
8712+ SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, hsvclr.h, brightness));
8713+ }
8714+ }
86928715 }
86938716 }
86948717
8718+ // palette mode and not filling: smear-blur to cover up palette wrapping artefacts
8719+ if(!SEGMENT.check1 && SEGMENT.palette)
8720+ SEGMENT.blur(200, true);
8721+
86958722 return FRAMETIME;
86968723}
8697- static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = "Distortion Waves@!,Scale;;;2 ";
8724+ static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = "Distortion Waves@!,Scale,,,,Fill,Zoom,Alt;;!;2;pal=0 ";
86988725
86998726
87008727//Soap
0 commit comments