For blending between two colors, here's a bit of mixing code:
i tend to like this a little bit more, especially if I can reuse the color lambda
Or another lambda version https://gist.github.com/zeffii/5354106
abbreviated here:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# color_filters.py | |
filter_color = {'r': 0.9, 'g': 0.2, 'b': 0.1} | |
background_color = {'r': 0.9, 'g': 0.9, 'b': 0.4} | |
filter_alpha = 0.7 | |
def over_operator(alpha, color1, color2): | |
color_out = {} | |
for component in color1.keys(): | |
color_out[component] = \ | |
(alpha * color1[component]) + ((1.0-alpha) * color2[component]) | |
return color_out | |
new_color = over_operator(filter_alpha, filter_color, background_color) | |
for component in 'rgb': | |
print(component, new_color[component]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# color_filters.py | |
# full version https://gist.github.com/zeffii/5355384 | |
col = lambda r, g, b : dict(zip('rgb', (r, g, b))) | |
filter_color = col(0.9, 0.2, 0.1) | |
background_color = col(0.9, 0.9, 0.4) | |
filter_alpha = 0.7 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# color_filters.py | |
col = lambda rgb : dict(zip('rgb', rgb)) | |
filter_color = col((0.9, 0.2, 0.1)) | |
background_color = col((0.9, 0.9, 0.4)) | |
filter_alpha = 0.7 | |
# rest is the same |