Last active
June 23, 2021 15:56
-
-
Save guillaume-chevalier/62afc6b46df18c5e77fb2e51016ba4f3 to your computer and use it in GitHub Desktop.
Print a one line ASCII console animation in Python
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
# Example output: | |
# .-'¯ _,.-'¯ _,.-'¯ _,.-'¯ _,.-'¯ | your message here |.,_ ¯'-.,_ ¯'-.,_ ¯'-.,_ ¯'-.,_ ¯ | |
# The things next to the message are animated and moving. | |
import time | |
import sys | |
import os | |
def wait(): | |
_, cols = os.popen('stty size', 'r').read().split() | |
cols = int(cols) | |
# You can choose or create a different animation pattern: | |
# chars = "_.~\"|" | |
# chars = "\"`-._,-'" | |
# chars = """|/-.-\\|/-'-\\""" | |
# chars = """|/-\\|/-\\""" | |
chars = "_,.-'¯ " | |
message = "| your message here |" | |
cols -= len(message) | |
half_cols = int(cols/2) | |
for i in range(100000): | |
time.sleep(0.07) | |
sys.stdout.write("\r" + | |
"".join([chars[(i + j) % len(chars)] for j in range(half_cols)]) + | |
message + | |
"".join([chars[(i - j) % len(chars)] for j in range(half_cols)]) | |
) | |
sys.stdout.flush() | |
# print("") # uncomment this line to print many lines, filling up the whole screen. | |
wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment