     }
  
     private func generateMartinArt(width: Int, height: Int) -> CGImage? {
+        print("\(width) \(height)")
+        self.width = width
+        self.height = height
         let colorSpace = CGColorSpaceCreateDeviceRGB()
         let bytesPerPixel = 4
         let bitsPerComponent = 8

        
        var currentPixel = pixelBuffer
        
        var r = [[Int]](count: height, repeatedValue: [Int](count: width, repeatedValue: 0))
        var g = [[Int]](count: height, repeatedValue: [Int](count: width, repeatedValue: 0))
        var b = [[Int]](count: height, repeatedValue: [Int](count: width, repeatedValue: 0))
        
        for j in 0 ..< height {
            for i in 0 ..< width {
                let r = martin_pixel_r(i, h: j)
                let g = martin_pixel_g(i, h: j)
                let b = martin_pixel_b(i, h: j)
                
                currentPixel.memory = RGB32(red: r, green: g, blue: b, alpha: UInt8(255))
                currentPixel += 1

            }
        }
        
        return nil
    }
    
    private func martin_pixel_r(w: Int, h: Int) -> UInt8 {
        if r[w][h] == 0 {
            r[w][h] = floor(Float(arc4random()) / Float(UINT32_MAX) * 999) == 0 ? UInt8(floor(Float(arc4random()) / Float(UINT32_MAX) * 256)) : martin_pixel_r(w + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width), h: h + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width))
        }
        
        return r[w][h]
    }

    private func martin_pixel_g(w: Int, h: Int) -> UInt8 {
        if g[w][h] == 0 {
            g[w][h] = floor(Float(arc4random()) / Float(UINT32_MAX) * 999) == 0 ? UInt8(floor(Float(arc4random()) / Float(UINT32_MAX) * 256)) : martin_pixel_g(w + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width), h: h + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width))
        }
        
        return g[w][h]
    }
    
    private func martin_pixel_b(w: Int, h: Int) -> UInt8 {
        if b[w][h] == 0 {
            b[w][h] = floor(Float(arc4random()) / Float(UINT32_MAX) * 999) == 0 ? UInt8(floor(Float(arc4random()) / Float(UINT32_MAX) * 256)) : martin_pixel_b(w + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width), h: h + Int(floor(Float(arc4random()) / Float(UINT32_MAX) * 2)) % Int(self.bounds.width))
        }
        
        return b[w][h]
    }
    
    struct RGB32 {


class MartinView: UIView {

    var width: Int = 0
    var height: Int = 0;
    
    override func drawRect(rect: CGRect) {
        if let img = generateMartinArt(Int(rect.width), height: Int(rect.height)) {
