CattailArtNSColor is an Objective C Class you can use in your Cocoa application project that provides functions to get arrays of NSColor objects based on a root color and your chosen art method (complement, triad, tetradic, etc.).
Dynamically building eye-pleasing color schemes. Fine-tuning gradients beyond the simple 2-color ones.
#import "CattailArtNSColor.h"
NSColor *rootColor = [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:1.0]; NSArray *colors = [CattailArtNSColor NewtonFlameArray:rootColor numberOfColorsInt:3 hueStepDegreesCGFloat: 60.0 saturationStepDegreesCGFloat: 0.0 brightnessStepDegreesCGFloat:15.0 alignmentInt:1];
// This is something you can do within a NSView subclass. NSGradient *gradient = [[NSGradient alloc] initWithColors:colors]; [gradient drawInRect:[self bounds] angle:270];
// This is my favorite gradient that looks like a sunset. NSColor *rootColorBlue = [NSColor colorWithCalibratedRed:0.0 green:0.5 blue:1.0 alpha:1.0]; NSColor *rootColorRed = [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:1.0]; NSArray *colorsBlue = [CattailArtNSColor RGBFlameArray:rootColorBlue numberOfColorsInt:3 hueStepDegreesCGFloat: 15.0 saturationStepDegreesCGFloat: 0.0 brightnessStepDegreesCGFloat:30.0 alignmentInt:-1]; NSArray *colorsRed = [CattailArtNSColor NewtonFlameArray:rootColorRed numberOfColorsInt:3 hueStepDegreesCGFloat: 60.0 saturationStepDegreesCGFloat: 0.0 brightnessStepDegreesCGFloat:15.0 alignmentInt:1]; NSMutableArray *colors = [[NSMutableArray alloc] init]; [colors addObjectsFromArray:colorsBlue]; [colors addObjectsFromArray:colorsRed]; [gradientView setGradient:colors];
See the code in action in my CattailArtNSColorDemo:
http://cattail.nu/mac/applications/CattailArtNSColorDemo/
rootColor | NSColor object that the array will be built from. |
tetradicDegreesCGFloat |
CGFloat that defines how many degrees apart the tetradic colors should be. 0.0 to 360.0. |
numberOfColorsInt | Integer that is the number of colors to return in the array. For analogous, saturation, value, chromatic, and flame colors. |
stepDegreesCGFloat | CGFloat that defines how much difference there is between colors. 0.0 to 360.0 for hue. 0.0 to 100.0 for saturation and value. |
alignmentInt | Integer to specify where the rootColor appears in a flame array. alignment = -1 (left) 0 (center) or 1 (right). |
The code is provided as-is and will likely get updated as I find things to change. It's also one of my learning projects so it may not be totally streamlined and I highly recommend you read it before you implement it. If you find things that could be done better, please let me know (preferably with a working code fix): T@cattail.nu
Change History:
2009-01-12: Created.