Skip to content

Instantly share code, notes, and snippets.

@fitsum
Last active October 6, 2020 20:59
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 fitsum/66e16380b7dc6ec55fcc1582c16c8dfa to your computer and use it in GitHub Desktop.
Save fitsum/66e16380b7dc6ec55fcc1582c16c8dfa to your computer and use it in GitHub Desktop.
based on fun cascading thing I used to do manually on twitter
// OG
// https://jsfiddle.net/fitsum/40t8h2no/
// params
s:String = string
f:String = filler character
e:String = effect name; eg. "rev", "zig"
w:Number = horizontal spacing
const ASCIIcade = (s, f = null, e = null, w = 3) => {
let out = "";
let words = s.toUpperCase().split(" ");
let maxlen = [...words].sort((a, b) => b.length - a.length)[0].length;
let fill = !!f ? f : "+";
let direction = false;
words.forEach((word, idx) => {
direction = !direction;
word = !!f ? word + Array(maxlen - word.length).fill(f).join("") : word;
word = e === "rev" || e === "zig" && direction === false ? word.split("").reverse().join("") : word;
out += word.split("").reduce((acc, char, idx) => {
let spaceCount = e === "rev" || e === "zig" && direction === false ? word.length * w - idx * w - w : idx * w;
let spacer = Array(spaceCount).fill(" ").join("");
return acc + spacer + char + "\n";
}, "\n")
});
return out;
}
// eg
ASCIIcade("holy fuck")
// returns
H
O
L
Y
F
U
C
K
f("holy fuck",'', 'rev')
// returns
Y
L
O
H
K
C
U
F
//TODO: reverse order of chars in zig's zag
//TODO: much refactor
//FIXME: garbled UNICODE
//TODO: in twitter app - note total char count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment