Skip to content

Instantly share code, notes, and snippets.

@shmup
Forked from rupa/-
Created May 12, 2014 17:04
Show Gist options
  • Save shmup/9769ff01ccc6546dca53 to your computer and use it in GitHub Desktop.
Save shmup/9769ff01ccc6546dca53 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import random
CHARS = {
'top': [
u'\u0300',
u'\u0301',
u'\u0302',
u'\u0303',
u'\u0304',
u'\u0305',
u'\u0306',
u'\u0307',
u'\u0308',
u'\u0309',
u'\u030A',
u'\u030B',
u'\u030C',
u'\u030D',
u'\u030E',
u'\u030F',
u'\u0310',
u'\u0311',
u'\u0312',
u'\u0313',
u'\u0314',
u'\u0315',
u'\u031A',
u'\u031B',
u'\u033D',
u'\u033E',
u'\u033F',
u'\u0340',
u'\u0341',
u'\u0342',
u'\u0343',
u'\u0344',
u'\u0346',
u'\u034A',
u'\u034B',
u'\u034C',
u'\u0350',
u'\u0351',
u'\u0352',
u'\u0357',
u'\u0358',
u'\u035B',
u'\u035D',
u'\u035E',
u'\u0360',
u'\u0361',
u'\u0363',
u'\u0364',
u'\u0365',
u'\u0366',
u'\u0367',
u'\u0368',
u'\u0369',
u'\u036A',
u'\u036B',
u'\u036C',
u'\u036D',
u'\u036E',
u'\u036F',
],
'bottom': [
u'\u0316',
u'\u0317',
u'\u0318',
u'\u0319',
u'\u031C',
u'\u031D',
u'\u031E',
u'\u031F',
u'\u0320',
u'\u0321',
u'\u0322',
u'\u0323',
u'\u0324',
u'\u0325',
u'\u0326',
u'\u0327',
u'\u0328',
u'\u0329',
u'\u032A',
u'\u032B',
u'\u032C',
u'\u032D',
u'\u032E',
u'\u032F',
u'\u0330',
u'\u0331',
u'\u0332',
u'\u0333',
u'\u0339',
u'\u033A',
u'\u033B',
u'\u033C',
u'\u0345',
u'\u0347',
u'\u0348',
u'\u0349',
u'\u034D',
u'\u034E',
u'\u0353',
u'\u0354',
u'\u0355',
u'\u0356',
u'\u0359',
u'\u035A',
u'\u035C',
u'\u035F',
u'\u0362',
],
'middle': [
u'\u0489',
u'\u0334',
u'\u0335',
u'\u0336',
u'\u0337',
u'\u0338',
],
}
def zalg(c, level=1, top=False, middle=False, bottom=False, same=False):
'''
zalgo a character.
'''
if top:
if same:
yield random.choice(CHARS['top']) * random.randrange(level + 1)
else:
for j in range(random.randrange(level + 1)):
yield random.choice(CHARS['top'])
if middle:
# try to stay legible
if not random.randrange(2):
yield random.choice(CHARS['middle'])
if bottom:
if same:
yield random.choice(CHARS['bottom']) * random.randrange(level + 1)
else:
for j in range(random.randrange(level + 1)):
yield random.choice(CHARS['bottom'])
yield c
def char(c, func, *args, **kwargs):
return u' ' if c == ' ' else ''.join(func(c, *args, **kwargs))
def line(w, func, *args, **kwargs):
return u''.join(char(c, func, *args, **kwargs) for c in w)
if __name__ == '__main__':
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--level', type=int, default=5)
parser.add_argument('-s', '--same', action='store_true')
parser.add_argument('-t', '--top', action='store_true')
parser.add_argument('-m', '--middle', action='store_true')
parser.add_argument('-b', '--bottom', action='store_true')
opts, args = parser.parse_known_args()
if not any([opts.top, opts.middle, opts.bottom]):
opts.top = True
if args:
lines = [' '.join(args)]
else:
lines = sys.stdin.readlines()
for l in lines:
print line(
l.strip(),
zalg,
level=opts.level,
top=opts.top,
middle=opts.middle,
bottom=opts.bottom,
same=opts.same,
).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment