Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- import os
- import sys
- def clear_screen():
- if os.name == 'posix':
- _ = os.system('clear')
- else:
- _ = os.system('cls')
- def get_terminal_size():
- size = os.get_terminal_size()
- return size.columns, size.lines
- # Automatically calculate terminal size
- WINDOW_WIDTH, WINDOW_HEIGHT = get_terminal_size()
- # Adjust as necessary to fit your terminal's character dimensions and desired appearance
- WINDOW_HEIGHT -= 1 # Adjusting to leave space for prompt visibility
- SPEED = 0.05 # Lower is faster
- def generate_color():
- """Generates a random color in RGB format."""
- emphasize_color = random.choice(['R', 'G', 'B'])
- if emphasize_color == 'R':
- color_value = random.randint(95, 255)
- return f'\033[38;2;{color_value};0;0m'
- elif emphasize_color == 'G':
- color_value = random.randint(95, 255)
- return f'\033[38;2;0;{color_value};0m'
- elif emphasize_color == 'B':
- color_value = random.randint(95, 255)
- return f'\033[38;2;0;0;{color_value}m'
- def generate_char():
- return chr(random.randint(0x30A0, 0x30FF)) # Japanese characters range
- def print_at_pos(x, y, char, color):
- sys.stdout.write(f"\033[{y};{x}H{color}{char}\033[0m")
- def init_matrix():
- return [[' ' for _ in range(WINDOW_WIDTH)] for _ in range(WINDOW_HEIGHT)]
- def update_matrix(matrix):
- for x in range(WINDOW_WIDTH):
- if random.randint(0, 10) < 2:
- matrix[0][x] = generate_char()
- else:
- matrix[0][x] = ' '
- for y in range(WINDOW_HEIGHT - 1, 0, -1):
- for x in range(WINDOW_WIDTH):
- matrix[y][x] = matrix[y-1][x]
- def print_matrix(matrix):
- for y in range(WINDOW_HEIGHT):
- for x in range(WINDOW_WIDTH):
- char = matrix[y][x]
- if char != ' ':
- print_at_pos(x+1, y+1, char, generate_color())
- def main():
- clear_screen()
- matrix = init_matrix()
- try:
- while True:
- update_matrix(matrix)
- print_matrix(matrix)
- time.sleep(SPEED)
- except KeyboardInterrupt:
- clear_screen()
- sys.exit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement