Skip to content

Instantly share code, notes, and snippets.

@gregzanch
Created December 21, 2019 03:33
Show Gist options
  • Save gregzanch/573c65140200c659ecd9c4e594b2f8b7 to your computer and use it in GitHub Desktop.
Save gregzanch/573c65140200c659ecd9c4e594b2f8b7 to your computer and use it in GitHub Desktop.
Concatenation of an es6 template literal with arguments.
/**
* 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