Created
March 30, 2022 00:08
-
-
Save dharmapurebuddha/2801911bdbeef4252ba1561621a5de42 to your computer and use it in GitHub Desktop.
A Python Poem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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