Skip to content

Instantly share code, notes, and snippets.

@juliendargelos
Last active August 2, 2021 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliendargelos/79b6f4ba93a9699860e74220e2b2441d to your computer and use it in GitHub Desktop.
Save juliendargelos/79b6f4ba93a9699860e74220e2b2441d to your computer and use it in GitHub Desktop.
Arithmetic mapping function that scales a vec2 buffer array
/**
* Creates a mapping function that scales a vec2 buffer array
*
* @param {number} x x scale
* @param {number} y y scale
* @return {function} method to pass to Array.prototype.map
*
* @example
*
* [
* -0.5, -0.5,
* -0.5, 0.5,
* 0.5, -0.5,
* 0.5, 0.5
* ].map(scale(2, 3))
*
* // [
* // -1, -1.5,
* // -1, 1.5,
* // 1, -1.5,
* // 1, 1.5
* // ]
*/
const scale = (x, y) => (v, i) => v * ((i + 1) % 2 * x + i % 2 * y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment