import math import random one = 'And am I born to die? ' two = 'What will become of me? ' def latex(phrase: str, dx: float, dy: float, size: int, color: str) -> str: x = '' if dx == 0 else f'\\hspace{{{dx}em}}' y = phrase if dy == 0 else f'\\raisebox{{{dy}em}}{{{phrase}}}' return f'\\fontspec{{Gentium Book Plus}}[Color={color},Ligatures=TeX]{x}{y}\n' def html(phrase: str, dx: int, dy: int, size: int, color: float) -> str: return f'{phrase}\n' def graphomania(): latex_file = open('graphomania.tex', 'w') html_file = open('graphomania.html', 'w') for i in range(1, 500): r = random.randint(1, 500) rx = random.randint(1, 500) ry = random.randint(1, 500) dx = 0 dy = 0 size = 0 color = 1 dir = (r % 3) -1 if r < i and dir != 0: # Todo: # - text size # - color dx = dir * ((float(i - r) % float(rx) / (r - i) * 10) % 15.0) dy = dir * ((float(i - r) % float(ry) / (r - i) * 10) % 15.0) color = 1 - (r / i) phrase = random.choice([two for p in range(0, i)] + [one for p in range(i, 500)]) html_file.write(html(phrase, dx, dy, size, color)) for i in range(1, 150): r = random.randint(1, 150) rx = random.randint(1, 150) ry = random.randint(1, 150) dx = 0 dy = 0 size = 0 color = '000000' dir = (r % 3) -1 if r < i and dir != 0: # Todo: # - text size # - color dx = (float(i - r * dir) % float(rx) / (r - i) * 10) % 15.0 dy = (float(i - r * dir) % float(ry) / (r - i) * 10) % 15.0 color = str(hex(math.floor((i - r) % 16)))[2] * 6 phrase = random.choice([two for p in range(0, i)] + [one for p in range(i, 250)]) latex_file.write(latex(phrase, dx * 1.2, dy, size, color)) latex_file.close() html_file.close() graphomania()