Skip to content

Instantly share code, notes, and snippets.

@mattrajca
Created August 5, 2012 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrajca/3266625 to your computer and use it in GitHub Desktop.
Save mattrajca/3266625 to your computer and use it in GitHub Desktop.
Generating pinstripes with JSTalk and Acorn
var acorn = [JSTalk application:"Acorn"];
var w = 640;
var h = 960;
var stripeW = 20;
var spaceW = 20;
var foregroundColor = [NSColor redColor];
var backgroundColor = [NSColor blueColor];
var newImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:null pixelsWide:w pixelsHigh:h bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:w * 4 bitsPerPixel:32];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:newImage]];
[backgroundColor set];
NSRectFill(NSMakeRect(0, 0, w, h));
[foregroundColor set];
for (var x = 0; x < w; x += (stripeW + spaceW)) {
NSRectFill(NSMakeRect(x, 0, stripeW, h));
}
[NSGraphicsContext restoreGraphicsState];
[[acorn sharedDocumentController] newDocumentWithImageData:[newImage TIFFRepresentation]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment