Last active
January 18, 2016 18:45
-
-
Save pfreixes/a911dd6e17aca6bcc6a2 to your computer and use it in GitHub Desktop.
Animations with Python and terminal output
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
# More info about ANSI escape sequences | |
# http://ascii-table.com/ansi-escape-sequences.php | |
import sys | |
import random | |
from time import sleep | |
ROWS = 10 | |
while True: | |
for i in range(0, ROWS): | |
sys.stdout.write("*"*random.randint(1, 10) + "\n") | |
sys.stdout.flush() | |
sleep(1) | |
for i in range(0, ROWS): | |
sys.stdout.write("\033[K") # remove line | |
sys.stdout.write("\033[1A") # up the cursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment