Last active
August 29, 2015 14:20
Revisions
-
petebarber revised this gist
May 3, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,6 @@ private func drawGrassIntoBitmap(bitmap: NSBitmapImageRep) path.stroke() path.fill() } let SIZE = CGSize(width: 800, height: 400) -
petebarber revised this gist
May 3, 2015 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,6 @@ private func saveAsPNGWithName(fileName: String, bitMap: NSBitmapImageRep) -> Bo let props: [NSObject:AnyObject] = [:] let imageData = bitMap.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: props) return imageData!.writeToFile(fileName, atomically: false) } @@ -35,8 +33,6 @@ private func drawGrassIntoBitmap(bitmap: NSBitmapImageRep) let SIZE = CGSize(width: 800, height: 400) if Process.arguments.count != 2 { println("usage: grass <file>") @@ -46,4 +42,4 @@ if Process.arguments.count != 2 let grass = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(SIZE.width), pixelsHigh: Int(SIZE.height), bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSDeviceRGBColorSpace, bytesPerRow: 0, bitsPerPixel: 0) drawGrassIntoBitmap(grass!) saveAsPNGWithName(Process.arguments[1], grass!) -
petebarber created this gist
May 2, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ import Cocoa private func saveAsPNGWithName(fileName: String, bitMap: NSBitmapImageRep) -> Bool { let props: [NSObject:AnyObject] = [:] let imageData = bitMap.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: props) let myPath = NSFileManager.defaultManager().currentDirectoryPath return imageData!.writeToFile(fileName, atomically: false) } private func drawGrassIntoBitmap(bitmap: NSBitmapImageRep) { var ctx = NSGraphicsContext(bitmapImageRep: bitmap) NSGraphicsContext.setCurrentContext(ctx) NSColor(red: 124 / 255, green: 252 / 255, blue: 0, alpha: 1.0).set() let path = NSBezierPath() path.moveToPoint(NSPoint(x: 0, y: 0)) for i in stride(from: 0, through: SIZE.width, by: 40) { path.lineToPoint(NSPoint(x: CGFloat(i + 20), y: CGFloat(arc4random_uniform(400)))) path.lineToPoint(NSPoint(x: i + 40, y: 0)) } path.stroke() path.fill() } let SIZE = CGSize(width: 800, height: 400) println("\(Process.arguments[0])") if Process.arguments.count != 2 { println("usage: grass <file>") exit(1) } let grass = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(SIZE.width), pixelsHigh: Int(SIZE.height), bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSDeviceRGBColorSpace, bytesPerRow: 0, bitsPerPixel: 0) drawGrassIntoBitmap(grass!) saveAsPNGWithName(Process.arguments[1], grass!)