Created
May 12, 2025 05:49
-
-
Save Xnuvers007/89a905f2460d95f2e2acb5e123712d6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import time | |
from threading import Thread, Lock | |
import sys | |
lock = Lock() | |
BLUE = '\033[94m' | |
RESET = '\033[0m' | |
def animate_text(text, delay=0.1, color_info=None): | |
with lock: | |
use_BLUE = True | |
for char in text: | |
if color_info and char == color_info: | |
color = f"{BLUE}{char}{RESET}" if use_BLUE else char | |
sys.stdout.write(color) | |
use_BLUE = not use_BLUE | |
else: | |
sys.stdout.write(char) | |
sys.stdout.flush() | |
time.sleep(delay) | |
print() | |
def sing_lyric(lyric, delay, speed, color_char): | |
time.sleep(delay) | |
animate_text(lyric, speed, color_char) | |
def sing_song(): | |
lyrics = [ | |
("\nA A A A A A A A A A Aku akan beritahu pada dunia", 0.08, 'A'), | |
("kau begitu indah", 0.08, None), | |
("yang pernah ku punya", 0.08, None), | |
("A A A A Aku akan selalu menemani dirimu", 0.08, 'A'), | |
("U U U U U U Ucap Terima kasih untuk dirimu", 0.09, 'U'), | |
("kita membuat memori sampai akhir hayat nanti", 0.08, None), | |
("cinta ku tak pernah mati jadi kau tak perlu worry", 0.07, None), | |
("genggam tanganku tak perlu ragu", 0.08, None), | |
("habiskan waktu hanya bersama dirimu", 0.08, None), | |
] | |
delays = [0.3, 5.0, 6.8, 8.0, 11.3, 15.3, 18.6, 22.7, 26.0] | |
threads = [] | |
for i in range(len(lyrics)): | |
lyric, speed, color_char = lyrics[i] | |
t = Thread(target=sing_lyric, args=(lyric, delays[i], speed, color_char)) | |
threads.append(t) | |
t.start() | |
for thread in threads: | |
thread.join() | |
if __name__ == "__main__": | |
sing_song() |
This file contains hidden or 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
import time | |
from threading import Thread, Lock | |
import sys | |
lock = Lock() | |
RED = '\033[91m' | |
RESET = '\033[0m' | |
def animate_text(text, delay=0.1, color_info=None): | |
with lock: | |
use_red = True | |
for char in text: | |
color = f"{RED}{char}{RESET}" if color_info and char == color_info else char | |
sys.stdout.write(color) | |
sys.stdout.flush() | |
if color_info and char == color_info: | |
use_red = not use_red | |
time.sleep(delay) | |
print() | |
def sing_lyric(lyric, delay, speed, color_char): | |
time.sleep(delay) | |
animate_text(lyric, speed, color_char) | |
def sing_song(): | |
lyrics = [ | |
("\nA A A A A A A A A A Aku akan beritahu pada dunia", 0.08, 'A', 0.3), | |
("kau begitu indah", 0.08, None, 5.0), | |
("yang pernah ku punya", 0.08, None, 6.8), | |
("A A A A Aku akan selalu menemani dirimu", 0.08, 'A', 8.0), | |
("U U U U U U Ucap Terima kasih untuk dirimu", 0.09, 'U', 11.3), | |
("kita membuat memori sampai akhir hayat nanti", 0.08, None, 15.3), | |
("cinta ku tak pernah mati jadi kau tak perlu worry", 0.07, None, 18.6), | |
("genggam tanganku tak perlu ragu", 0.08, None, 22.7), | |
("habiskan waktu hanya bersama dirimu", 0.08, None, 26.0) | |
] | |
threads = [ | |
Thread(target=sing_lyric, args=(lyric, delay, speed, color_char)) | |
for lyric, speed, color_char, delay in lyrics | |
] | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
if __name__ == "__main__": | |
sing_song() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment