Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guillaume-chevalier/62afc6b46df18c5e77fb2e51016ba4f3 to your computer and use it in GitHub Desktop.
Save guillaume-chevalier/62afc6b46df18c5e77fb2e51016ba4f3 to your computer and use it in GitHub Desktop.
Print a one line ASCII console animation in Python
# 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