Graphomania
This commit is contained in:
71
idumea/graphomania.py
Normal file
71
idumea/graphomania.py
Normal file
@ -0,0 +1,71 @@
|
||||
import math
|
||||
import random
|
||||
|
||||
|
||||
one = 'And am I born to die? '
|
||||
two = 'What will become of me? '
|
||||
|
||||
|
||||
def latex(phrase: str, dx: int, dy: int, 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}}}'
|
||||
extra = '' if math.floor(dx + dy) % 2 == 0 else '\n'
|
||||
return f'\\fontspec{{Gentium Book Plus}}[Scale=0.9,Color={color},Ligatures=TeX]{x}{y}{extra}\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, 200):
|
||||
r = random.randint(1, 200)
|
||||
rx = random.randint(1, 200)
|
||||
ry = random.randint(1, 200)
|
||||
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, 200)])
|
||||
|
||||
latex_file.write(latex(phrase, dx, dy, size, color))
|
||||
|
||||
latex_file.close()
|
||||
html_file.close()
|
||||
|
||||
graphomania()
|
||||
Reference in New Issue
Block a user