Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # helper function to generate color gradient:
- def hex_to_RGB(hex):
- ''' "#FFFFFF" -> [255,255,255] '''
- # Pass 16 to the integer function for change of base
- return [int(hex[i:i+2], 16) for i in range(1,6,2)]
- # helper function to generate color gradient:
- def linear_gradient(start_hex, finish_hex="#FFFFFF", n=307):
- ''' returns a gradient list of (n) colors between
- two hex colors. start_hex and finish_hex
- should be the full six-digit color string,
- inlcuding the number sign ("#FFFFFF") '''
- # Starting and ending colors in RGB form
- s = hex_to_RGB(start_hex)
- f = hex_to_RGB(finish_hex)
- # Initilize a list of the output colors with the starting color
- RGB_list = ["rgb(%s, %s, %s)" % (s[0], s[1], s[2])]
- # 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 = [int(s[j] + (float(t)/(n-1))*(f[j]-s[j])) for j in range(3)]
- # Add it to our list of output colors
- RGB_list.append("rgb(%s, %s, %s)" % (curr_vector[0], curr_vector[1], curr_vector[2]))
- RGB_list.reverse()
- return RGB_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement