A color gradient is a smooth color progression from one color to another, which creates the illusion of continuity between the two color extremes.
The following function may be used used to create color gradients.
This function returns a list of RGB colors (i.e., a list of lists) starting with color1 (e.g., [0, 0, 0]) and ending (without including) color2 (e.g., [251, 147, 14], which is orange). The number of steps equals the number of colors in the list returned.
For example, the following creates a gradient list of 12 colors:
>>> colorGradient([0, 0, 0], [251, 147, 14], 12) [[0, 0, 0], [20, 12, 1], [41, 24, 2], [62, 36, 3], [83, 49, 4], [104, 61, 5], [125, 73, 7], [146, 85, 8], [167, 98, 9], [188, 110, 10], [209, 122, 11], [230, 134, 12]]
Notice how the above excludes the final color (i.e., [251, 147, 14]). This allows to create composite gradients (without duplication of colors). For example, the following:
black = [0, 0, 0] # RGB values for black orange = [251, 147, 14] # RGB values for orange white = [255, 255, 255] # RGB values for white cg = colorGradient(black, orange, 12) + colorGradient(orange, white, 12) + [white]
creates a list of gradient colors from black to orange, and from orange to white. Notice how the final color, white, has to be included separately (using list concatenation). Now, gc contains a total of 25 unique gradient colors.