Created
August 5, 2012 18:42
-
-
Save mattrajca/3266625 to your computer and use it in GitHub Desktop.
Generating pinstripes with JSTalk and Acorn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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