import type { IReset } from "@thi.ng/api" ; import { AGen } from "./agen.js" ; param period param start export const impulseTrain = ( period , start ? ) => new ImpulseTrain ( 1 , 0 , period , start ) ; export const impulseTrainT = < T > ( on , off , period , start ? ) => new ImpulseTrain ( on , off , period , start ) ; export const impulseTrainB = ( period , start ? ) => new ImpulseTrain ( true , false , period , start ) ; export class ImpulseTrain < T > extends AGen < T > implements IReset { protected _startpos : number ; constructor ( protected _on , protected _off , protected _period , protected _pos = 0 ) { super ( _off ) ; this . _startpos = -- this . _pos ; } reset ( ) { this . _val = this . _off ; this . _pos = this . _startpos ; return this ; } next ( ) { return ( this . _val = ++ this . _pos >= this . _period ? ( ( this . _pos = 0 ) , this . _on ) : this . _off ) ; } }