def linear_gradient(start_hex, finish_hex="#FFFFFF", n=10):
"""Returns a gradient list of (n) colors between
two hex colors. start_hex and finish_hex
should be the full six-digit color string,
including the number sign ("#FFFFFF")
Code from http://bsou.io/posts/color-gradients-with-python
"""
# Starting and ending colors in RGB form
s = hex2color(start_hex)
f = hex2color(finish_hex)
# Initialize a list of the output colors with the starting color
RGB_list = [rgb2hex(s)]
# Calcuate a color at each evenly spaced value of t from 1 to n
for t in range(1, n):
# Interpolate RGB vector for color at the current value of t
curr_vector = [s[j] + (t / (n - 1)) * (f[j] - s[j])
for j in range(3)]
# Add it to our list of output colors
RGB_list.append(rgb2hex(curr_vector))
return RGB_list
评论列表
文章目录