random

- collection of un-sorted bollocks
git clone git://git.acid.vegas/random.git
Log | Files | Refs | Archive

zalgo.py (1135B)

      1 #!/usr/bin/env python
      2 # -*- coding: utf-8 -*-
      3 # zalgo text - developed by acidvegas in python (https://acid.vegas/random)
      4 
      5 from random import randint, choice
      6 
      7 def zalgo(text, intensity=50):
      8 	zalgo_chars = [chr(i) for i in range(0x0300, 0x036F + 1)]
      9 	zalgo_chars.extend([u'\u0488', u'\u0489'])
     10 	if not _is_narrow_build:
     11 		text = _insert_randoms(text)
     12 	zalgoized = []
     13 	for letter in text:
     14 		zalgoized.append(letter)
     15 		for _ in range(randint(0, intensity) + 1):
     16 			zalgoized.append(choice(zalgo_chars))
     17 	response = choice(zalgo_chars).join(zalgoized)
     18 	return response
     19 
     20 def _insert_randoms(text):
     21 	random_extras = [unichr(i) for i in range(0x1D023, 0x1D045 + 1)]
     22 	newtext = []
     23 	for char in text:
     24 		newtext.append(char)
     25 		if randint(1, 5) == 1:
     26 			newtext.append(choice(random_extras))
     27 	return u''.join(newtext)
     28 
     29 def _is_narrow_build():
     30 	try:
     31 		chr(0x10000)
     32 	except ValueError:
     33 		return True
     34 	return False
     35 
     36 for i in range(100):
     37 	print(zalgo('This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test This is a test '))