KALAPASTANGAN
unknown
python
3 months ago
1.1 kB
34
Indexable
import sys
import time
# lyrics + total typing seconds + pause seconds
lyrics = [
("Oh, ang langit ay nandito lamang pala sa lupa", 7, 2),
("At ang impiyerno ay nasa isipan ko, at pinalimot ng 'Yong ganda", 10, 1),
("Umaawit ang mga anghel,", 4, 1),
("umaawit ang mga anghel", 4, 2),
("Nagdiriwang sila nang makasama Kita,", 4, 1),
("huwag Ka sanang mawawala", 3, 0),
]
def type_out(text, total_time):
if len(text) == 0:
return
# calculate delay per character
delay = total_time / len(text)
# safety clamp so it never gets too fast
if delay < 0.02:
delay = 0.02
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
# new line after line is done
sys.stdout.write("\n")
sys.stdout.flush()
# make sure output uses utf-8 (important on windows)
try:
sys.stdout.reconfigure(encoding="utf-8")
except AttributeError:
pass
for line, write_time, pause_time in lyrics:
type_out(line, write_time)
time.sleep(pause_time)
Editor is loading...
Leave a Comment