Skip to content

Instantly share code, notes, and snippets.

@frostbitten
Last active August 28, 2016 09:23
Show Gist options
  • Save frostbitten/82e8e29917715f1742f1d834d38bed26 to your computer and use it in GitHub Desktop.
Save frostbitten/82e8e29917715f1742f1d834d38bed26 to your computer and use it in GitHub Desktop.
coolors.co convert to adobe color (kuler)

Convert Coolors.co palette to Adobe Color (Kuler) link

convert-coolors-kuler-banner.png

Example usage

Utilize the coolors2kuler() function to convert a coolors palette link to a kuler link :

coolors2kuler("https://coolors.co/2f1847-624763-c62e65-f9b3d1-d63af9")
  => "https://color.adobe.com/create/color-wheel/?rule=Custom&mode=rgb&rgbvalues=0.1843137254901961,0.09411764705882353,0.2784313725490196,0.3843137254901961,0.2784313725490196,0.38823529411764707,0.7764705882352941,0.1803921568627451,0.396078431372549,0.9764705882352941,0.7019607843137254,0.8196078431372549,0.8392156862745098,0.22745098039215686,0.9764705882352941"

or, if you have your browser console open on Coolors, paste contents of coolors2kuler.js then freely use:

coolors2kuler(colors)

This works because colors is a global variable of the current color palette.

/*
Example usage:
coolors2kuler("https://coolors.co/2f1847-624763-c62e65-f9b3d1-d63af9")
=> "https://color.adobe.com/create/color-wheel/?rule=Custom&mode=rgb&rgbvalues=0.1843137254901961,0.09411764705882353,0.2784313725490196,0.3843137254901961,0.2784313725490196,0.38823529411764707,0.7764705882352941,0.1803921568627451,0.396078431372549,0.9764705882352941,0.7019607843137254,0.8196078431372549,0.8392156862745098,0.22745098039215686,0.9764705882352941"
*/
coolors2kuler= function(colors){
// http://fiddle.jshell.net/ZsrM6/light/
var hex2rgb = function(hex) {
if (hex.lastIndexOf('#') > -1) {
hex = hex.replace(/#/, '0x');
} else {
hex = '0x' + hex;
}
var r = hex >> 16;
var g = (hex & 0x00FF00) >> 8;
var b = hex & 0x0000FF;
return [r, g, b];
};
if(typeof colors === "object" && colors.length == 5){
}else{
if(colors.indexOf('https://coolors.co/') === 0) {
colors = colors.slice('https://coolors.co/'.length);
}
var colors = colors.split('-');
}
var rgb_colors = [];
var kuler_colors = [];
colors.forEach(function(c){
var c_rgb = hex2rgb(c);
rgb_colors.push(c_rgb);
var c_kuler = [];
c_rgb.forEach(function(d){
c_kuler.push(d/255);
});
kuler_colors.push(c_kuler);
});
console.log('rgb_colors:',rgb_colors);
console.log('kuler_colors:',kuler_colors);
var link = 'https://color.adobe.com/create/color-wheel/?rule=Custom&mode=rgb&rgbvalues=';
for(i=0;i<kuler_colors.length;i++){
for(ii=0;ii<3;ii++){
if(!(0 === i && i === ii))
link += ",";
link += kuler_colors[i][ii];
}
}
return link;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment