Skip to content

Instantly share code, notes, and snippets.

@nornagon
Created January 24, 2021 01:36
Show Gist options
  • Save nornagon/522afb55c648d6fa6d12831d0ca99928 to your computer and use it in GitHub Desktop.
Save nornagon/522afb55c648d6fa6d12831d0ca99928 to your computer and use it in GitHub Desktop.
Example of microtracery usage
<body>
<script>
// Micro-size tracery implementation by @nornagon: https://twitter.com/nornagon/status/1322718632481153025
function tracery(data, s='#origin#') {return s.replace(/#([^#]+?)#/g, (_,m) => (_=data[m]??[`((${m}))`],tracery(data, _[(Math.random()*_.length)|0])))}
// Example usage
const text = tracery({
origin: ["#a#", "#b#"],
a: ["a1", "a2"],
b: ["b1", "b2"],
})
document.body.textContent = text
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment