I am trying to create a function to calculate tint based off a given rgb value and given number of tints. So the user will give an rgb value such as (100,200,150) as well as how many tints they want to be printed. The program will then print out that many colors with the first color printed, being the color given and then each color after that getting brighter till it reaches white, which is (255,255,255).
For example: User input: red = 255, green = 0, blue=0, and numTints = 5
This will print: red,brighter red,brighter red,brighter red,white
The user can enter how ever many tints they want.
I understand that I need to multiply each rgb value by a constant greater than one until each value reaches 255. What I need help with is how to find that contant to multiply each value by.
First, create a function that takes two integers and returns numbers that lie evenly spaced between them. Then apply that function to each of your red, blue, and green channels of your colors.
"""returns a list of length `size` whose elements are evenly distributed between start and end"""
def interpolate(start, end, size):
delta = float(end - start) / (size-1)
return [start + i*delta for i in range(size)]
def interpolate_color(start, end, size):
red = interpolate(start[0], end[0], size)
green = interpolate(start[1], end[1], size)
blue = interpolate(start[2], end[2], size)
return zip(red, green, blue)
start = (100,200,150)
end = (255,255,255)
for c in interpolate_color(start, end, 5):
print c
Result:
(100.0, 200.0, 150.0)
(138.75, 213.75, 176.25)
(177.5, 227.5, 202.5)
(216.25, 241.25, 228.75)
(255.0, 255.0, 255.0)