Skip to content

Instantly share code, notes, and snippets.

@HamGuy
Created July 4, 2014 08:19
Show Gist options
  • Save HamGuy/64461e83c8f460f9c7af to your computer and use it in GitHub Desktop.
Save HamGuy/64461e83c8f460f9c7af to your computer and use it in GitHub Desktop.
Lores drawr with cocoa platground
// Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
let colors = [NSColor.blackColor(),NSColor.blueColor(),NSColor.greenColor(),NSColor.brownColor(),NSColor.cyanColor(),NSColor.yellowColor(),NSColor.magentaColor(),NSColor.orangeColor(),NSColor.purpleColor(),NSColor.whiteColor()];
func clearScreen(screen:NSRect){
NSColor.blackColor().setFill();
NSRectFill(screen);
}
func plot(x:Int,y:Int){
NSRectFill(NSRect(x: 16*x, y: 10*y, width: 16, height: 10))
}
func setColor(index:Int){
if index < colors.count{
colors[index].setFill()
}
}
class Lores:NSView{
override func drawRect(dirtyRect: NSRect) {
clearScreen(dirtyRect)
for i in 1..39{
for j in 1..39{
setColor((i+j)%colors.count)
plot(i, j);
}
}
}
}
//show
Lores(frame: NSRect(x: 0, y: 0, width: 640, height: 400))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment