Gabe C.

asked • 11/11/21

Python gradient RGB

I am creating a PYTHON program that outputs a window with a background made up of lines that start at

x = 0 and span across the width of the window. What I would like to do is ask the user for starting and stopping points of colors specifically RGB, with the output creating a gradient-colored background depending on the data inputted.

This is a sample of my program with the portion of code I am working on for this particular question. I am doing this essentially from scratch, only importing random and a custom GUI for the drawing window.


def main():  

window_w= int(input("Width: ")) # input desired dimensions of the drawing window

window_h= int(input("Height: "))


red1 = int(input("Begin? ")) # asks the user for start and stop of each RGB

green1 = int(input("Begin? "))

blue1 = int(input("Begin? "))

red2 = int(input("End? "))

green2 = int(input("End? "))

blue2 = int(input("End? "))


red = (red_stop - red_start ) / window_w # find the difference between stop and start and divide by the windows width

green = (green_stop - green_start) / window_w # not sure if this is the right idea and I am not sure how I would actually use this

blue = (blue_stop - blue_start) / window_w # in the color portion of the line drawing because I get invalid color errors


counter = 0

while count < panel_width:  # lines are drawn across the window while the counter is less than the windows width

window.draw_line(counter , 0, counter, window_h)

counter = counter + 1

window.sleep(500)


main()


2 Answers By Expert Tutors

By:

Evan S. answered • 12/16/21

Tutor
4.7 (7)

Computer Science and Math Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.