# =========================================================
# GALAXY RGB ULTRA
# =========================================================

import random
import time
import math
import shutil

# =========================================================
# TERMINAL SIZE
# =========================================================

WIDTH, HEIGHT = shutil.get_terminal_size()

HEIGHT -= 2

# =========================================================
# ANSI COLORS
# =========================================================

RESET = "\033[0m"

CORES = [

    "\033[91m",  # vermelho
    "\033[92m",  # verde
    "\033[93m",  # amarelo
    "\033[94m",  # azul
    "\033[95m",  # roxo
    "\033[96m",  # cyan
    "\033[97m",  # branco

]

# =========================================================
# ESTRELAS
# =========================================================

stars = []

for i in range(450):

    stars.append({

        "x": random.randint(
            0,
            WIDTH-1
        ),

        "y": random.randint(
            0,
            HEIGHT-1
        ),

        "speed": random.choice([
            0.2,
            0.4,
            0.7,
            1,
            1.5,
            2
        ]),

        "char": random.choice([
            ".",
            "*",
            "+",
            "·"
        ]),

        "color": random.choice(
            CORES
        )

    })

# =========================================================
# CLEAR
# =========================================================

def clear():
    print("\033[H\033[J", end="")

# =========================================================
# LOOP
# =========================================================

t = 0

while True:

    # =====================================
    # TELA
    # =====================================

    tela = [

        [" " for x in range(WIDTH)]

        for y in range(HEIGHT)

    ]

    # =====================================
    # ESTRELAS
    # =====================================

    for s in stars:

        x = int(s["x"])
        y = int(s["y"])

        if 0 <= x < WIDTH and 0 <= y < HEIGHT:

            tela[y][x] = (

                s["color"]

                +

                s["char"]

                +

                RESET

            )

        # =================================
        # MOVIMENTO
        # =================================

        s["x"] -= s["speed"]

        # movimento vertical leve

        s["y"] += math.sin(
            t + s["x"] * 0.03
        ) * 0.08

        # =================================
        # RESET
        # =================================

        if s["x"] < 0:

            s["x"] = WIDTH-1

            s["y"] = random.randint(
                0,
                HEIGHT-1
            )

            s["speed"] = random.choice([
                0.2,
                0.4,
                0.7,
                1,
                1.5,
                2
            ])

            s["char"] = random.choice([
                ".",
                "*",
                "+",
                "·"
            ])

            s["color"] = random.choice(
                CORES
            )

    # =====================================
    # EFEITOS EXTRAS
    # =====================================

    for i in range(8):

        mx = random.randint(
            0,
            WIDTH-1
        )

        my = random.randint(
            0,
            HEIGHT-1
        )

        tela[my][mx] = (

            random.choice(CORES)

            +

            "✦"

            +

            RESET

        )

    # =====================================
    # PRINT
    # =====================================

    clear()

    for linha in tela:

        print("".join(linha))

    # =====================================
    # VELOCIDADE
    # =====================================

    t += 0.03

    time.sleep(0.02)
