# Ian Binstock
# 6/3/2026
# DVD example where color changes when DVD bounces off of a wall.

import pygame, sys, random, time
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((677, 420))
pygame.display.set_caption("Notes")

black = pygame.Color(0,0,0)
rainbow = pygame.Color(255,0,0)
clock = pygame.time.Clock()

# Our initial settings
x = 50
y = 50
dx = 2
dy = 2

def changeColor():
    color = pygame.Color(0, 0, 0)

    nice = False
    while not nice:
        r = random.randint(100, 255)
        g = random.randint(100, 255)
        b = random.randint(100, 255)

        if abs(r-g) > 100 or abs(r-b) > 100 or abs(g-b) > 100:
            nice = True
            color = pygame.Color(r, g, b)

    return color

# DISPLAYSURF.fill(black)
# cnt = 0
while True:
    # We just look to see if the user wants to exit.
    for event in pygame.event.get():

        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    # Translate our object for the next frame.
    x += dx
    y += dy

    # update rainbow color
    # nice = False
    # if cnt == 0:
    #     while not nice:
    #         r = random.randint(100, 255)
    #         g = random.randint(100, 255)
    #         b = random.randint(100, 255)

    #         if abs(r-g) > 50 and abs(r-b) > 50 and abs(g-b) > 50:
    #             nice = True
    #             rainbow = pygame.Color(r, g, b)

    # cnt = (cnt + 1) % 30

    # x = x % 1000
    # y = y % 600

    # This does our bounce by changing the velocity component.
    if x >= 677 - 100 or x <= 0:
        dx = -dx
        rainbow = changeColor()

    if y >= 420 - 55 or y <= 0:
        dy = -dy
        rainbow = changeColor()

    # Draw, update and wait!
    DISPLAYSURF.fill(black)
    pygame.draw.rect(DISPLAYSURF, rainbow, (x, y, 100, 55), 0)
    pygame.display.update()
    clock.tick(300)
