Skip to content

Instantly share code, notes, and snippets.

@y13i
Created June 26, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y13i/28478459a76aaabfd605decff7de0362 to your computer and use it in GitHub Desktop.
Save y13i/28478459a76aaabfd605decff7de0362 to your computer and use it in GitHub Desktop.
// todo: use https://github.com/transitive-bullshit/random
function rnorm() {
return (
Math.sqrt(-2 * Math.log(1 - Math.random())) *
Math.cos(2 * Math.PI * Math.random())
);
}
function textpand(text, length = text.length, sd = 0) {
return [...new Array(length)]
.map(
(_, i) =>
text[
Math.min(
Math.max(Math.floor((text.length * i) / length + rnorm() * sd), 0),
text.length - 1
)
]
)
.join("");
}
console.log(textpand("unko", 140, 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment