# Maria Mauco
# 6/7/24
# Turtle gradient

import turtle

# Chage color mode to rgb
turtle.colormode(255)

# Change speed and shape of turtle
turtle.shape("turtle")
turtle.speed(0)

# Set screen size
screen = turtle.getscreen() 
screenWidth = 800
screenHeight = 700
screen.setup(screenWidth, screenHeight)
screen.bgcolor("black") # Makes the background black

# Ask the user for the level of gradience
rects = int(input("How many rectangles would you like to make the gradint? "))

# Calculates the height of each rectangle
rectHeight = screenHeight/rects

# Sets turtle to the bottom left of the screen to start
turtle.setx((screenWidth /2)* -1)
turtle.sety((screenHeight/2)* -1)

# Starting rgb values
r = 255
g = 10
b = 55

# Find the level of change each rectangle should have in color. 
# if we want to change blue from 55 to 255, and draw 10 rectangles, 
# the color should increase by 20 values for every rectangle
change = 200//rects

# Stores the value of the new y value
newY = (screenHeight/2)* -1

# Loop to draw the number of rectangles the user wants
for i in range(rects):
    turtle.pencolor(r,g,b) # makes the pen color this value too

    # Starts the fill of the rectangle
    turtle.fillcolor(r,g,b)
    turtle.begin_fill()

    # For loop to draw a rectangle
    for j in range(2):
        turtle.forward(screenWidth)
        turtle.left(90)
        turtle.forward(rectHeight)
        turtle.left(90)
        
    turtle.end_fill() # ends the fill

    # Changes the r and b values by the change we calculated
    r -= change
    b += change

    # Sets the new position of the turtle
    newY += rectHeight
    turtle.setx((screenWidth /2)* -1)
    turtle.sety(newY)

    


    
    

