I think this does essentially the same thing as what's in the video:
from time import sleep
CPS = 3 # Update speed in Characters Per Second.
def run(text, width=60, delay=1/CPS):
text = text.replace('\n', '') # Removed any newlines.
for i in range(len(text)+1):
print('\r' + text[:i].center(width), end="", flush=True)
sleep(delay)
for i in range(len(text)+1, -1, -1):
print('\r' + text[:i].center(width), end="", flush=True)
sleep(delay)
run("Hello\n")
run("world")
The code above can be streamlined slightly by applying the DRY (Don't Repeat Yourself) principle of software development:
from itertools import chain
from time import sleep
CPS = 3 # Update speed in Characters Per Second.
def run(text, width=50, delay=1/CPS):
for line in text.splitlines():
interval = len(line) + 1
for i in chain(range(interval), range(interval, -1, -1)):
print('\r' + line[:i].center(width), end="", flush=True)
sleep(delay)
run("Hello\nworld")