Created
June 12, 2015 23:09
-
-
Save evanmiltenburg/3bd3772e6803c8718a32 to your computer and use it in GitHub Desktop.
Script to easily obtain lists of RGB tuples from a .txt file containing URLs from colorcombos.com
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
from urlparse import urlparse | |
import colorsys, sys | |
def keyword_tuples(query): | |
"""Create (keyword,value) tuples for the query.""" | |
return map(lambda x:tuple(x.split('=')), query.split('&')) | |
def get_colors(url): | |
"""Get colors from the URL, returns a list of hex color values (without #)""" | |
result = urlparse(url) | |
query = dict(keyword_tuples(result.query)) | |
return query['colors'].split(',') | |
def hex_to_rgb(value): | |
"""Convert hex to RGB""" | |
lv = len(value) | |
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) | |
if __name__ == "__main__": | |
with open('colorcombos.txt') as f: | |
for line in f: | |
print map(hex_to_rgb, get_colors(line.strip())) |
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
http://www.colorcombos.com/combomaker.html?design=&output_width=0&size_option=&colors=4D8963,69A583,E1B378,E0CC97,EC799A,9F0251&background_color=&show_hex_flag= | |
http://www.colorcombos.com/combomaker.html?design=&output_width=0&size_option=&colors=A31E39,485C5A,8C9C9A,9DB2B1,BFCFCC,D6E4E1&background_color=&show_hex_flag= | |
http://www.colorcombos.com/combomaker.html?design=&output_width=0&size_option=&colors=6194BC,A5D1F3,D0EAFF,E4001B,ECECEC,606060&background_color=&show_hex_flag= | |
http://www.colorcombos.com/combomaker.html?design=squares&output_width=100&size_option=element&colors=E65400,742068,234483,0C637C,018982,476475,50544D&background_color=&show_hex_flag=Y | |
http://www.colorcombos.com/combomaker.html?design=squares&output_width=100&size_option=element&colors=027878,FDB632,2BC444,10C5CD,9EF3EB,02782A,F2F39E,C22326&background_color=&show_hex_flag=Y | |
http://www.colorcombos.com/combomaker.html?design=squares&output_width=75&size_option=element&colors=21B6A8,177F75,B67721,7F171F,B6212D&background_color=&show_hex_flag=Y | |
http://www.colorcombos.com/combomaker.html?design=circles&output_width=75&size_option=element&colors=3498DB,44BBFF,897FBA,71BA51,DF554F,FCD036,ED5784,FF7416,2C2C2C,8A8A8A,EEEEEE&background_color=&show_hex_flag=Y |
While this code is useful, the wordcloud does not have a parameter to mention the "color palettes" or custom colors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Every page on www.colorcombos.com (e.g. this one) has a link saying 'copy combo'. This script exists to make my life easier by extracting color combos directly from that link. Just copy+paste links of nice combos to the colorcombos.txt file and run the script. This is particularly useful for my fork of the word_cloud module, which enables users to specify their own color palettes.