I found a few differences between the original code formulas and yours, minor but significant in effect, like using a2 instead of a3 (I think that was it)
Here’s a slider heavy version, intended to let someone play with all of the variables until they find an effect they like…
Some changes, including…
-
Using wave(time()) rather than time() to avoid what I found were distracting ‘flash changes’ when something went from 1 to 0… also without millis(), we really don’t have a long ‘t’ to replace it. @wizard, consider this a plea for some way to emulate that, but we also don’t really have anything longer than a 16.16 number, which doesn’t really help us here. millis() is used in the original (and many other patterns) as the driving force, since it’ll grow to 4,294,967,295 (32 unsigned) before it rolls over.
-
Log scale sliders, so picking values below and above 1 was easier.
-
Decoupled the time bases… that’s another change from the original code… in Original, time then time/2 then time/3, but in your code above, you grew the time base by x2 and x3
Distortion Waves TNG, with sliders upon sliders
// original code by ldirko_Yaroslaw Turbin 17-06-2021
// https://twitter.com/ldir_ko https://vk.com/ldirko
// https://www.youtube.com/c/ldirldir https://www.reddit.com/user/ldirko/
// original code: https://editor.soulmatelights.com/gallery/1089-distorsion-waves
// and https://wokwi.com/arduino/projects/301639284294681097
// modified/recoded by @pixie at https://forum.electromage.com/t/wled-pattern-porting/1295/22
// then re-modified quite a bit by Scruffynerf
// simple replacement for original LUTs
function cos_wave(proportion) { return 1-wave(proportion+0.25); }
function beatsin(bpm) { return wave(time(0.91552734375/bpm)); }
// adjustments - all sliders now
export var timeBase1 = 0.2;
export var timeBase2 = 0.1;
export var timeBase3 = 0.66;
export var speed = 4;
export var w = .05;
export var scalefactor = .5;
export var coeff1,coeff2,coeff3
export function sliderSpeed(v){
speed = v*9.9
}
var minv = log(.1);
var maxv = log(3);
export function sliderScale(v){
scalefactor = exp(minv + (maxv-minv)*v);
}
var minv2 = log(.01);
export function sliderWiggle(v){
w = exp(minv2 + (maxv-minv2)*v);
}
var maxv2 = log(30);
export function sliderTime1(v){
timeBase1 = exp(minv2 + (maxv2-minv2)*v) +.0001
}
export function sliderTime2(v){
timeBase2 = exp(minv2 + (maxv2-minv2)*v) +.0001
}
export function sliderTime3(v){
timeBase3 = exp(minv2 + (maxv2-minv2)*v) +.0001
}
coeff1 = 1;
coeff2 = 1;
coeff3 = 1;
export function sliderC1(v){
coeff1 = exp(minv + (maxv-minv)*v);
}
export function sliderC2(v){
coeff2 = exp(minv + (maxv-minv)*v);
}
export function sliderC3(v){
coeff3 = exp(minv + (maxv-minv)*v);
}
export function beforeRender(delta) {
resetTransform()
//translate(-.5, -.5)
scale(scalefactor,scalefactor)
a1=wave(time(timeBase1*2))*2-1;
a2=wave(time(timeBase2*2))*2-1;
a3=wave(time(timeBase3*2))*2-1;
cx1 = beatsin(10-speed)
cx2 = beatsin(13-speed)
cx3 = beatsin(17-speed)
cy1 = beatsin(12-speed)
cy2 = beatsin(15-speed)
cy3 = beatsin(14-speed)
}
// debugging uncomment -
// export var _r,_g,_b,cx1,cx2,cx3,cy1,cy2,cy3,dx1,dx2,dx3,dy1,dy2,dy3
export function render2D(index, x, y) {
r1 = coeff1*cos_wave(x+a1);
g1 = coeff1*cos_wave(x-a2);
b1 = coeff1*cos_wave(x+a3);
r2 = coeff2*cos_wave(y-a2);
g2 = coeff2*cos_wave(y+a3);
b2 = coeff2*cos_wave(y-a1);
rdistort = coeff3*cos_wave(r1+r2+a3);
gdistort = coeff3*cos_wave(g1+g2+a1+1/8);
bdistort = coeff3*cos_wave(b1+b2+a2+1/4);
dx1 = (x-cx1)*(x-cx1);
dx2 = (x-cx2)*(x-cx2);
dx3 = (x-cx3)*(x-cx3);
dy1 = (y-cy1)*(y-cy1);
dy2 = (y-cy2)*(y-cy2);
dy3 = (y-cy3)*(y-cy3);
_r = rdistort + w*(a1-(dx1 + dy1))
_g = gdistort + w*(a2-(dx2 + dy2))
_b = bdistort + w*(a3-(dx3 + dy3))
rgb(_r*_r, _g*_g, _b*_b);
}