class Plasma implements Effect { private width : number ; private height : number ; public async init ( width , height ) { this . width = width ; this . height = height ; } public render ( ctx , t ) { const dest = ctx . getImageData ( 0 , 0 , this . width , this . height ) ; const time = t / 500 ; let ofs = 0 ; for ( let y = 0 ; y < this . height ; y ++ ) { const dy = ( y / this . height ) - 0.5 ; for ( let x = 0 ; x < this . width ; x ++ ) { const dx = ( x / this . width ) - 0.5 ; let v = Math . sin ( dx * 10 + time ) ; const cx = dx + 0.5 * Math . sin ( time / 5 ) ; const cy = dy + 0.5 * Math . cos ( time / 3 ) ; v += Math . sin ( Math . sqrt ( 50 * ( cx * cx + cy * cy ) + 1 + time ) ) ; v += Math . cos ( Math . sqrt ( dx * dx + dy * dy ) - time ) ; const r = Math . floor ( Math . sin ( v * Math . PI ) * 255 ) ; const b = Math . floor ( Math . cos ( v * Math . PI ) * 255 ) ; dest . data [ ofs ++ ] = r ; dest . data [ ofs ++ ] = 0 ; dest . data [ ofs ++ ] = b ; dest . data [ ofs ++ ] = 0xff ; } } ctx . putImageData ( dest , 0 , 0 ) ; } } demoFX . register ( "plasma" , new Plasma ( ) ) ;