Last active
August 2, 2021 20:32
-
-
Save juliendargelos/79b6f4ba93a9699860e74220e2b2441d to your computer and use it in GitHub Desktop.
Arithmetic mapping function that scales a vec2 buffer array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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