Skip to content

Instantly share code, notes, and snippets.

@st-j
Forked from niw/create_color_list.m
Last active August 29, 2015 14:04
Show Gist options
  • Save st-j/c20e7465d751c9b7b11b to your computer and use it in GitHub Desktop.
Save st-j/c20e7465d751c9b7b11b to your computer and use it in GitHub Desktop.
create_color_list
Colors.clr
#!/bin/sh
clang -framework AppKit create_color_list.m -o create_color_list
// compile with: clang -framework AppKit create_color_list.m -o create_color_list
#import <AppKit/AppKit.h>
int main(int argc, char *argv[])
{
@autoreleasepool {
NSColorList *colorList = [[NSColorList alloc] initWithName:@"Colors"];
if (argc < 2) {
printf("Usage: %s name:rrggbb,name:rrggbb,...\n", argv[0]);
return 0;
}
NSString *colors = [NSString stringWithUTF8String:argv[1]];
for (NSString *colorString in [colors componentsSeparatedByString:@","]) {
NSString *key;
NSArray *keyAndColor = [colorString componentsSeparatedByString:@":"];
if ([keyAndColor count] > 1) {
key = keyAndColor[0];
colorString = keyAndColor[1];
} else {
key = [NSString stringWithFormat:@"#%@", [colorString lowercaseString]];
}
NSScanner *scanner = [NSScanner scannerWithString:colorString];
unsigned int colorInt;
[scanner scanHexInt:&colorInt];
CGFloat r = (CGFloat)((colorInt >> 16) & 0xff) / 0xff;
CGFloat g = (CGFloat)((colorInt >> 8) & 0xff) /0xff;
CGFloat b = (CGFloat)((colorInt) & 0xff) / 0xff;
[colorList setColor:[NSColor colorWithRed:r green:g blue:b alpha:1.0f] forKey:key];
}
[colorList writeToFile:@"Colors.clr"];
return 0;
}
}
#!/bin/sh
./create_color_list \
"Solarized Base03":002b36,\
"Solarized Base02":073642,\
"Solarized Base01":586e75,\
"Solarized Base00":657b83,\
"Solarized Base0":839496,\
"Solarized Base1":93a1a1,\
"Solarized Base2":eee8d5,\
"Solarized Base3":cfcdc6,\
"Solarized Base4":fdfaf5,\
"Solarized Yellow":b58900,\
"Solarized Orange":cb4b16,\
"Solarized Red":dc322f,\
"Solarized Magenta":d33682,\
"Solarized Violet":6c71c4,\
"Solarized Blue":268bd2,\
"Solarized Cyan":2aa198,\
"Solarized Green":859900,\
"Solarized Bright Yellow":cf9c0c,\
"Solarized Bright Orange":fc3115,\
"Solarized Bright Red":fb0022,\
"Solarized Bright Magenta":fb007c,\
"Solarized Bright Violet":6862ff,\
"Solarized Bright Blue":2380ff,\
"Solarized Bright Cyan":31cab3,\
"Solarized Bright Green":9ec90b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment