'''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


def setRandomRGB(img):
    for x in range(img.getWidth()):
        for y in range(img.getHeight()):
            # make all pixel values on left side blue
            if x < 100:
                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
    myImg = gr.Image(gr.Point(0, 0), width, height)

    # Call function to set all pixels to random RGB colors
    setRandomRGB(myImg)

    # Display the image in a new window
    screen = display.displayImage(myImg, 'My rainbow image!')

    # display image until we get a mouse click
    screen.getMouse()
    screen.close()
