fork download
  1. #Hẹn hò nhưng không yêu
  2. #Mọi người sài nhớ cre nha !!
  3. #code by Tranchinnn
  4. #code mang tính chia sẻ giải trí không toxic
  5. import sys
  6. import os
  7. import time
  8. import threading
  9.  
  10. def play_music(filename="music.mp3"):
  11. """
  12. Phát nhạc nền liên tục bằng pygame.
  13. Nếu pygame chưa cài,sẽ tự động cài nhé.
  14. """
  15. import contextlib, io
  16.  
  17. try:
  18. with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
  19. import pygame
  20. except ImportError:
  21. try:
  22. import subprocess
  23. with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
  24. subprocess.check_call([sys.executable, "-m", "pip", "install", "pygame"])
  25. import pygame
  26. except Exception:
  27. return
  28.  
  29. if not os.path.exists(filename):
  30. return
  31.  
  32. try:
  33. with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
  34. pygame.mixer.init()
  35. pygame.mixer.music.load(filename)
  36. pygame.mixer.music.play(-1)
  37. except Exception:
  38. return
  39.  
  40.  
  41. class Mau:
  42. RESET = '\033[0m'
  43. TRANG = (255, 255, 255)
  44. DEN = (50, 50, 50)
  45.  
  46. def xoa_man_hinh():
  47. """Xóa màn hình terminal"""
  48. os.system('cls' if os.name == 'nt' else 'clear')
  49.  
  50.  
  51.  
  52. def hieu_ung_tung_tu_ro_dan(line, char_speed=0.08, word_delay=0.3, fade_steps=6):
  53. words = line.split()
  54. displayed_line = ""
  55.  
  56. for word in words:
  57. for step in range(1, fade_steps + 1):
  58. intensity = int(Mau.TRANG[0] * (fade_steps - step + 1) / fade_steps)
  59. temp_line = displayed_line + f"\033[38;2;{intensity};{intensity};{intensity}m{word}{Mau.RESET} "
  60. sys.stdout.write(f"\r{temp_line}")
  61. sys.stdout.flush()
  62. time.sleep(char_speed)
  63. displayed_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{word}{Mau.RESET} "
  64. sys.stdout.write(f"\r{displayed_line}")
  65. sys.stdout.flush()
  66. time.sleep(word_delay)
  67.  
  68. print()
  69. return displayed_line
  70.  
  71. def hieu_ung_go_chu(line, char_speed=0.05):
  72. current_line = ""
  73. for char in line:
  74. current_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{char}{Mau.RESET}"
  75. sys.stdout.write(f"\r{current_line}")
  76. sys.stdout.flush()
  77. time.sleep(char_speed)
  78. print()
  79. return current_line
  80. def hieu_ung_laser(line, step_delay=0.03, laser_width=3):
  81. length = len(line)
  82. for pos in range(length + laser_width):
  83. temp_line = ""
  84. for i, c in enumerate(line):
  85. if pos - laser_width <= i <= pos:
  86. temp_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{c}{Mau.RESET}"
  87. else:
  88. temp_line += f"\033[38;2;{Mau.DEN[0]};{Mau.DEN[1]};{Mau.DEN[2]}m{c}{Mau.RESET}"
  89. sys.stdout.write(f"\r{temp_line}")
  90. sys.stdout.flush()
  91. time.sleep(step_delay)
  92. gray_value = 180
  93. final_line = f"\033[38;2;{gray_value};{gray_value};{gray_value}m{line}{Mau.RESET}"
  94. sys.stdout.write(f"\r{final_line}\n")
  95. sys.stdout.flush()
  96. return line
  97.  
  98. def show_lyrics():
  99. lyrics_list = [
  100. "Con tốt mang tên em mà anh lựa chọn bước đi.",
  101. "Hẹn hò nhưng không yêu, chắc em là kẻ mất trí",
  102. "Hẹn hò nhưng không yêu, thế yêu định nghĩa là gì?",
  103. "Chạy về người ngàn bước cớ sao người lại từ khước",
  104. "Một bước quay lại về phía em.",
  105. "Em cố trăm lần ",
  106. "chẳng bằng ai đó 1 phần",
  107. "Em cố trăm lần ",
  108. "chẳng bằng ai đó 1 phần",
  109. "Những khi anh nói anh cần.. ở đâu em cũng chạy đến bên anh.",
  110. "Mưa gió không ngại, chỉ ngại anh ở bên ai, rồi em phải cố nén lại từng cơn nhói đau trong lòng"
  111. ]
  112.  
  113. char_speed_list = [0.08, 0.07, 0.07, 0.07, 0.06, 0.01, 0.01, 0.01, 0.01, 0.056, 0.067]
  114. effect_order = [2, 1, 1, 2, 2, 0, 0, 0, 0, 2, 2] # các hiệu ứng từ (0,1,2)
  115.  
  116. xoa_man_hinh()
  117. for idx, line in enumerate(lyrics_list):
  118. effect_type = effect_order[idx]
  119. speed = char_speed_list[idx]
  120. if effect_type == 0:
  121. hieu_ung_tung_tu_ro_dan(line, char_speed=speed)
  122. elif effect_type == 1:
  123. hieu_ung_go_chu(line, char_speed=speed)
  124. else:
  125. hieu_ung_laser(line, step_delay=speed)
  126.  
  127. time.sleep(0.5)
  128.  
  129.  
  130. if __name__ == "__main__":
  131. music_thread = threading.Thread(target=play_music, args=("music.mp3",), daemon=True)
  132. music_thread.start()
  133. show_lyrics()
  134.  
Success #stdin #stdout 0.03s 25556KB
stdin
Standard input is empty
stdout
#Hẹn hò nhưng không yêu 
#Mọi người sài nhớ cre nha !! 
#code by Tranchinnn
#code mang tính chia sẻ giải trí không toxic
import sys
import os
import time
import threading

def play_music(filename="music.mp3"):
    """
    Phát nhạc nền liên tục bằng pygame.
    Nếu pygame chưa cài,sẽ tự động cài nhé.
    """
    import contextlib, io

    try:
        with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
            import pygame
    except ImportError:
        try:
            import subprocess
            with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
                subprocess.check_call([sys.executable, "-m", "pip", "install", "pygame"])
                import pygame
        except Exception:
            return  

    if not os.path.exists(filename):
        return

    try:
        with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
            pygame.mixer.init()
            pygame.mixer.music.load(filename)
            pygame.mixer.music.play(-1)  
    except Exception:
        return


class Mau:
    RESET = '\033[0m'
    TRANG = (255, 255, 255)
    DEN = (50, 50, 50)

def xoa_man_hinh():
    """Xóa màn hình terminal"""
    os.system('cls' if os.name == 'nt' else 'clear')



def hieu_ung_tung_tu_ro_dan(line, char_speed=0.08, word_delay=0.3, fade_steps=6):
    words = line.split()
    displayed_line = ""

    for word in words:
        for step in range(1, fade_steps + 1):
            intensity = int(Mau.TRANG[0] * (fade_steps - step + 1) / fade_steps)
            temp_line = displayed_line + f"\033[38;2;{intensity};{intensity};{intensity}m{word}{Mau.RESET} "
            sys.stdout.write(f"\r{temp_line}")
            sys.stdout.flush()
            time.sleep(char_speed)
        displayed_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{word}{Mau.RESET} "
        sys.stdout.write(f"\r{displayed_line}")
        sys.stdout.flush()
        time.sleep(word_delay)

    print()
    return displayed_line

def hieu_ung_go_chu(line, char_speed=0.05):
    current_line = ""
    for char in line:
        current_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{char}{Mau.RESET}"
        sys.stdout.write(f"\r{current_line}")
        sys.stdout.flush()
        time.sleep(char_speed)
    print()
    return current_line
def hieu_ung_laser(line, step_delay=0.03, laser_width=3):
    length = len(line)
    for pos in range(length + laser_width):
        temp_line = ""
        for i, c in enumerate(line):
            if pos - laser_width <= i <= pos:
                temp_line += f"\033[38;2;{Mau.TRANG[0]};{Mau.TRANG[1]};{Mau.TRANG[2]}m{c}{Mau.RESET}"
            else:
                temp_line += f"\033[38;2;{Mau.DEN[0]};{Mau.DEN[1]};{Mau.DEN[2]}m{c}{Mau.RESET}"
        sys.stdout.write(f"\r{temp_line}")
        sys.stdout.flush()
        time.sleep(step_delay)
    gray_value = 180
    final_line = f"\033[38;2;{gray_value};{gray_value};{gray_value}m{line}{Mau.RESET}"
    sys.stdout.write(f"\r{final_line}\n")
    sys.stdout.flush()
    return line

def show_lyrics():
    lyrics_list = [
        "Con tốt mang tên em mà anh lựa chọn bước đi.",
        "Hẹn hò nhưng không yêu, chắc em là kẻ mất trí",
        "Hẹn hò nhưng không yêu, thế yêu định nghĩa là gì?",
        "Chạy về người ngàn bước cớ sao người lại từ khước",
        "Một bước quay lại về phía em.",
        "Em cố trăm lần ",
        "chẳng bằng ai đó 1 phần",
        "Em cố trăm lần ",
        "chẳng bằng ai đó 1 phần",
        "Những khi anh nói anh cần.. ở đâu em cũng chạy đến bên anh.",
        "Mưa gió không ngại, chỉ ngại anh ở bên ai, rồi em phải cố nén lại từng cơn nhói đau trong lòng"
    ]

    char_speed_list = [0.08, 0.07, 0.07, 0.07, 0.06, 0.01, 0.01, 0.01, 0.01, 0.056, 0.067]
    effect_order    = [2, 1, 1, 2, 2, 0, 0, 0, 0, 2, 2] # các hiệu ứng từ (0,1,2)

    xoa_man_hinh()
    for idx, line in enumerate(lyrics_list):
        effect_type = effect_order[idx]
        speed = char_speed_list[idx]
        if effect_type == 0:
            hieu_ung_tung_tu_ro_dan(line, char_speed=speed)
        elif effect_type == 1:
            hieu_ung_go_chu(line, char_speed=speed)
        else:
            hieu_ung_laser(line, step_delay=speed)

    time.sleep(0.5)


if __name__ == "__main__":
    music_thread = threading.Thread(target=play_music, args=("music.mp3",), daemon=True)
    music_thread.start()
    show_lyrics()