         switch nextPos
         {
         case 0: // up
-                y += 1
+                pos.y += 1
             
         case 1: // right
-                if (x%2)==1 {
-                    y -= 1
+                if (pos.x%2)==1 {
+                    pos.y -= 1
                 }
-                x += 1
+                pos.x += 1
 
         case 2: // left
-                if (x%2)==1 {
-                    y -= 1
+                if (pos.x%2)==1 {
+                    pos.y -= 1
                 }
-                x -= 1
+                pos.x -= 1
 
         case 3: // down
-                y -= 1
+                pos.y -= 1
                 skip = 0 // dont paint top
 
         case 4: // back left
-                if (x%2)==0 {
-                    y += 1
+                if (pos.x%2)==0 {
+                    pos.y += 1
                 }
-                x -= 1
+                pos.x -= 1
                 skip = 2 // dont paint right
 
         case 5: // back right
-                if (x%2)==0 {
-                    y += 1
+                if (pos.x%2)==0 {
+                    pos.y += 1
                 }
-                x += 1
+                pos.x += 1
                 skip = 1 // dont paint left
             
             default:
                 break
         }
 
-        if (x < 1 || y < 2 || x > nx-1 || y > ny-1) {
+        if (pos.x < 1 || pos.y < 2 || pos.x > nx-1 || pos.y > ny-1) {
 //            if reset == "center" {
 //                x = cx
 //                y = cy

        bPath.fill()
    }
    
    
    override func animateOneFrame() {
//        needsDisplay = true
//        setNeedsDisplayInRect(bounds)
        let context = window!.graphicsContext
        NSGraphicsContext.setCurrentContext(context)
        nextCube()
        context?.flushGraphics()
    }
    
    func nextCube()
    {
        var skip = -1
        var width = Int(bounds.size.width)
        var height = Int(bounds.size.height)

        var nx = Int(width/sizex)
        var ny = Int(height/sizey)

        nextPos = UInt(arc4random_uniform(6))
        lastPos = nextPos

    }
    
    func setup() {
        numrows = min(numrows, Int(bounds.size.height)/2)
    }
    
    override func drawRect(rect: NSRect) {
