Skip to content

Instantly share code, notes, and snippets.

@dharmapurebuddha
Created March 30, 2022 00:08
Show Gist options
  • Save dharmapurebuddha/2801911bdbeef4252ba1561621a5de42 to your computer and use it in GitHub Desktop.
Save dharmapurebuddha/2801911bdbeef4252ba1561621a5de42 to your computer and use it in GitHub Desktop.
A Python Poem
import math
import time
msg1 = 'I am a strange loop'
msg2 = 'I am a strange loop'
width = 25
def recurse(t):
x1 = math.floor(math.sin(t) * width + width)
x2 = math.floor(math.cos(t) * width + width)
j = max(len(msg1), len(msg2))
out1 = f'{" " * x1}{msg1}'.ljust(width * 2 + j, ' ')
out2 = f'{" " * x2}{msg2}'.ljust(width * 2 + j, ' ')
out = ""
for ch1, ch2 in zip(out1, out2):
if ch1 == ' ' and ch2 != ' ':
out += ch2
elif ch1 != ' ' and ch2 == ' ':
out += ch1
elif ch1 != ' ' and ch2 != ' ':
out += '.'
else:
out += ' '
print(out)
print(out)
t = 1.5
while True:
t += 0.03
recurse(t)
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment