71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
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:
|
|
result = phrase if dy == 0 else f'\\raisebox{{{dy}em}}{{{phrase}}}'
|
|
result = result if dx == 0 else f'\\shifttext{{{dx}em}}{{{result}}}'
|
|
return f'\\fontspec{{Gentium Book Plus}}[Color={color},Ligatures=TeX]{result}\n'
|
|
|
|
def html(phrase: str, dx: int, dy: int, size: int, color: float) -> str:
|
|
return f'<span style="position: relative; left: {dx}em; top: {dy}em; opacity: {color}">{phrase}</span>\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) % float(rx) / (r - i) * 10) % 15.0 * dir
|
|
dy = (float(i - r) % float(ry) / (r - i) * 10) % 15.0 * dir
|
|
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()
|