Skip to content

Instantly share code, notes, and snippets.

@gamefreak
Created September 28, 2011 01:56
Show Gist options
  • Save gamefreak/1246800 to your computer and use it in GitHub Desktop.
Save gamefreak/1246800 to your computer and use it in GitHub Desktop.
//gcc -framework Cocoa ./hdsize.m && ./a.out
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const int width = 100+75;
const int height = 400000+100;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(NULL, width, height, 5, 2 * width, cs, kCGImageAlphaNoneSkipFirst);
CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f);
CGContextFillRect(ctx, CGRectMake(0, 0, width, height));
CGContextSetRGBFillColor(ctx, 1.0f, .546875f, 0.0f, 1.0f);//ORANGE
CGContextFillRect(ctx, CGRectMake(25, 0, 25, 1));
CGContextSetRGBFillColor(ctx, 1.0f, 0.0f, 0.0f, 1.0f);//RED
CGContextFillRect(ctx, CGRectMake(50, 0, 25, 504));
CGContextSetRGBFillColor(ctx, 1.0f, .546875f, 0.0f, 1.0f);//ORANGE
CGContextFillRect(ctx, CGRectMake(100, 0, 25, 100000));
CGContextSetRGBFillColor(ctx, 1.0f, 0.0f, 0.0f, 1.0f);//RED
CGContextFillRect(ctx, CGRectMake(125, 0, 25, 400000));
CGImageRef image = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
CGColorSpaceRelease(cs);
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:image];
NSData *data = [rep representationUsingType:NSPNGFileType properties:nil];
[rep release];
[data writeToFile:@"/Users/scott/dev/chart.png" atomically:NO];
CGImageRelease(image);
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment