Skip to content

Instantly share code, notes, and snippets.

@sketchpunk
Created March 20, 2019 13:41
Show Gist options
  • Save sketchpunk/bfc4ba29e066eba7ea39d957ab176298 to your computer and use it in GitHub Desktop.
Save sketchpunk/bfc4ba29e066eba7ea39d957ab176298 to your computer and use it in GitHub Desktop.
triangleWaveInt
// Bounce back forth between 0 and Max
function triangleWaveInt( i, max ){
let max2 = max * 2;
i = i - Math.floor( i / max2 ) * max2; // sawtooth wave, but using a max value double
i = Math.max( 0, Math.min( max2, i )); // clamp
return max - Math.abs( i - max ); // triangle Wave
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment