Created
January 24, 2021 01:36
-
-
Save nornagon/522afb55c648d6fa6d12831d0ca99928 to your computer and use it in GitHub Desktop.
Example of microtracery usage
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
<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