Skip to content

Instantly share code, notes, and snippets.

@cvburgess
Created September 16, 2015 18:02
Show Gist options
  • Save cvburgess/19d730aa95cd15f18a79 to your computer and use it in GitHub Desktop.
Save cvburgess/19d730aa95cd15f18a79 to your computer and use it in GitHub Desktop.
Creates a tetrad color palette from a single UIColor
+ (NSArray*)tetradPaletteFromUIColor:(UIColor*)color {
NSMutableArray *palette = [[NSMutableArray alloc] init];
CGFloat primary_hue;
CGFloat saturation;
CGFloat brightness;
CGFloat alpha;
BOOL success = [color getHue:&primary_hue saturation:&saturation brightness:&brightness alpha:&alpha];
if ( success ) {
int primary_hue_degrees = primary_hue * 360.0;
for ( int i=0; i < 3; i++ ) {
int add_hue;
switch ( i ) {
case 0:
add_hue = 60;
break;
case 1:
add_hue = 180;
break;
case 2:
add_hue = 240;
break;
default:
add_hue = 0;
break;
}
[palette addObject:[UIColor colorWithHue:((primary_hue_degrees + add_hue) % 360 ) / 360.0
saturation:saturation
brightness:brightness
alpha:alpha]];
}
}
return [NSArray arrayWithArray:palette];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment