Created
December 21, 2019 03:33
-
-
Save gregzanch/573c65140200c659ecd9c4e594b2f8b7 to your computer and use it in GitHub Desktop.
Concatenation of an es6 template literal with arguments.
This file contains hidden or 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
/** | |
* This is a tagged template function for using inline glsl in javascript. | |
* Also helpful for inline html, css, etc. | |
* | |
* @param x this is the template literal split up by the arguments | |
* @param args the arguments passed in ${like.this} | |
* @returns {string} the joined string | |
* | |
* @example | |
* const frag = glsl` | |
* void main() { | |
* vec3 color = vec3(${Math.random()}); | |
* gl_FragColor = vec4(color,1.); | |
* }`; | |
* | |
*/ | |
const glsl = (x, ...args) => args ? x[0] + args.reduce((a, b, i) => a + b + x[i + 1], "") : x[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment