Skip to content

Commit

Permalink
gsuiPeriodicWave: use of GSUrealImagToXY
Browse files Browse the repository at this point in the history
  • Loading branch information
mr21 committed Feb 19, 2025
1 parent 0e7a6c7 commit 46f3fc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gs-utils
Submodule gs-utils updated 1 files
+18 −0 gs-utils.js
21 changes: 3 additions & 18 deletions gsuiPeriodicWave/gsuiPeriodicWave.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class gsuiPeriodicWave extends gsui0ne {
}

// .........................................................................
static $addWave( name, real, imag ) {
gsuiPeriodicWave.#cache[ name ] ||= GSUrealImagToXY( real, imag );
}
static #draw( wave, opt, w, h ) {
const hz = opt.frequency * opt.duration;
const amp = -opt.amplitude * .95 * h / 2;
Expand All @@ -83,24 +86,6 @@ class gsuiPeriodicWave extends gsui0ne {
}
return pts.join( " " );
}
static $addWave( name, real, imag ) {
if ( !gsuiPeriodicWave.#cache[ name ] ) {
const arr = [];
const fn = gsuiPeriodicWave.#getXFromWave.bind( null, real, imag );

for ( let x = 0; x < 256; ++x ) {
arr.push( fn( x / 256 ) );
}
gsuiPeriodicWave.#cache[ name ] = arr;
}
}
static #getXFromWave( a, b, t ) {
return a.reduce( ( val, ak, k ) => {
const tmp = Math.PI * 2 * k * t;

return val + ak * Math.cos( tmp ) + b[ k ] * Math.sin( tmp );
}, 0 );
}
}

GSUdefineElement( "gsui-periodicwave", gsuiPeriodicWave );

0 comments on commit 46f3fc6

Please sign in to comment.