'''lecture_18_rainbow_image_fun.py
Create a Zelle Image with random RGB values
Oliver W. Layton
CS151: Computational Thinking: Visual Media
Spring 2021
UPDATE 1: Make rows and columns of image between 0 and 99 (inclusive) pure blue
'''
import random

import display
import graphics as gr

    # for x in range(100):
    #     for y in range(100):


def setRandomRGB(img):
    for x in range(img.getWidth()):
        for y in range(img.getHeight()):
            # Goal: Fill in top 200x100 square region solid color of red. Random elsewhere
            # if x < 100 and y < 100:
            #     r = 255
            #     g = 0
            #     b = 0
            # else:
            #     r = random.randint(0, 255)
            #     g = random.randint(0, 255)
            #     b = random.randint(0, 255)

            # Goal: Fill in a blue vertical band between columns 200 and 400
            if x > 200 and x < 400:
                r = 0
                g = 0
                b = 255
            else:
                r = random.randint(0, 255)
                g = random.randint(0, 255)
                b = random.randint(0, 255)

            img.setPixel(x, y, gr.color_rgb(r, g, b))

            


# main code
if __name__ == '__main__':
    width = 512
    height = 256

    # Create an empty Image object
    rainbowImg = gr.Image(gr.Point(0, 0), width, height)

    # Call function to set all pixels to random RGB colors
    setRandomRGB(rainbowImg)

    # Display the image in a new window
    screen = display.displayImage(rainbowImg, 'My Rainbow Image')

    # display image until we get a mouse click
    screen.getMouse()
    screen.close()
