def interpolate_colors(colors, flat=False, num_colors=<NUM_LIT>):
palette = []<EOL>for i in range(num_colors):<EOL><INDENT>index = (i * (len(colors) - <NUM_LIT:1>)) / (num_colors - <NUM_LIT:1.0>)<EOL>index_int = int(index)<EOL>alpha = index - float(index_int)<EOL>if alpha > <NUM_LIT:0>:<EOL><INDENT>r = (<NUM_LIT:1.0> - alpha) * colors[index_int][<EOL><NUM_LIT:0>] + alpha * colors[index_int + <NUM_LIT:1>][<NUM_LIT:0>]<EOL>g = (<NUM_LIT:1.0> - alpha) * colors[index_int][<EOL><NUM_LIT:1>] + alpha * colors[index_int + <NUM_LIT:1>][<NUM_LIT:1>]<EOL>b = (<NUM_LIT:1.0> - alpha) * colors[index_int][<EOL><NUM_LIT:2>] + alpha * colors[index_int + <NUM_LIT:1>][<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>r = (<NUM_LIT:1.0> - alpha) * colors[index_int][<NUM_LIT:0>]<EOL>g = (<NUM_LIT:1.0> - alpha) * colors[index_int][<NUM_LIT:1>]<EOL>b = (<NUM_LIT:1.0> - alpha) * colors[index_int][<NUM_LIT:2>]<EOL><DEDENT>if flat:<EOL><INDENT>palette.extend((int(r), int(g), int(b)))<EOL><DEDENT>else:<EOL><INDENT>palette.append((int(r), int(g), int(b)))<EOL><DEDENT><DEDENT>return palette<EOL>
Given a list of colors, create a larger list of colors interpolating
    the first one. If flatten is True a list of numers will be returned. If
    False, a list of (r,g,b) tuples. num_colors is the number of colors wanted
    in the final list