Created
May 21, 2024 09:51
-
-
Save yannxou/a904f4de6e919d223e3b2570c94f2ad2 to your computer and use it in GitHub Desktop.
Zalgo text generator
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
// Zalgo text: https://en.wikipedia.org/wiki/Zalgo_text | |
func zalgo(_ string: String, intensity: Int = 5) -> String { | |
let combiningDiacriticMarks = 0x0300...0x036f | |
let latinAlphabetUppercase = 0x0041...0x005a | |
let latinAlphabetLowercase = 0x0061...0x007a | |
var output: [UnicodeScalar] = [] | |
for scalar in string.unicodeScalars { | |
output.append(scalar) | |
guard (latinAlphabetUppercase).contains(numericCast(scalar.value)) || | |
(latinAlphabetLowercase).contains(numericCast(scalar.value)) | |
else { | |
continue | |
} | |
for _ in 0...(Int.random(in: 1...intensity)) { | |
let randomScalarValue = Int.random(in: combiningDiacriticMarks) | |
output.append(Unicode.Scalar(randomScalarValue)!) | |
} | |
} | |
return String(String.UnicodeScalarView(output)) | |
} | |
let d = zalgo("Hello", intensity: 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment