Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

May I please know how to program this question in python? Thank you. You are tas

ID: 3709165 • Letter: M

Question

May I please know how to program this question in python? Thank you.

You are tasked with writing a program that will create a linear interpolation between two pixels. You are to read in two pixel values and generate a number of pixels specified between them.

For example:

Input for the program Enter the first colour: 0x002222 Enter the second colour: 8xFFDD33 Enter the number of colours to generate inbetween: 3 Using the 2 pixels specified it will generate 3 new pixels between the first and last pixel. You will need to round the difference of each channel between the larger and smaller pixel. (Edit, I have updated it so you need to round the channels not the pixels themselves). You will find the channel (Red, Green, Blue) difference between the two pixels and divide by the number of total pixels create the new pixels Colours: 0x002222 0x405126 0x80802a 0xceaf2e 0xffdd33 Your program will need to swap the starting pixel (or smallest) out of the two that were inputted should be the first colour shown while the larger pixel should be the last pixel specified.

Explanation / Answer

f_color = raw_input("Enter the first colour: ")

s_color = raw_input("Enter the second colour: ")

no_of_colors = raw_input("Enter the number of colours to generate in between: ")

no_of_colors = int(no_of_colors)

if int(f_color, 16) >= int(s_color, 16):

min_color = f_color

max_color = s_color

else:

min_color = s_color

max_color = f_color

max_color_data = [max_color[start:start + 2] for start in xrange(2, len(max_color), 2)]

min_color_data = [min_color[start:start + 2] for start in xrange(2, len(min_color), 2)]

output_colors = [min_color]

diff = []

for a,b in zip(max_color_data, min_color_data):

diff.append((int(a, 16) - int(b, 16)) / no_of_colors)

R = int(min_color_data[0], 16)

G = int(min_color_data[1], 16)

B = int(min_color_data[2], 16)

for i in range(no_of_colors):

R += diff[0]

G += diff[1]

B += diff[2]

color = hex(R * G * B)

output_colors.append(color)

output_colors.append(max_color)

for c in output_colors:

print c

//Sample output:

Enter the first colour: 0xccaaff

Enter the second colour: 0xff00ff

Enter the number of colours to generate in between: 3

0xff00ff

0x33dbf0

0x604f50

0x855a20

0xccaaff

Press any key to continue . . .