 
     override func viewDidLoad() {
         super.viewDidLoad()
-        let imageView = UIImageView(frame: viewMain.bounds)
-        imageView.image = UIImage(named: "dog.jpg")
-        imageView.contentMode = .ScaleAspectFit
         viewMain.addSubview(imageView)
         viewMain.addSubview(maskView)
     }


class ViewController: UIViewController {
    @IBOutlet var viewMain:UIView!
    var layers = [CALayer]()
    var xform = CGAffineTransformIdentity

    var builder = SNPathBuilder(minSegment: 8.0)
    lazy var shapeLayer:CAShapeLayer = {
        let layer = self.createShapeLayer()
        layer.opacity = 0.8
        self.viewMain.layer.addSublayer(layer)
        return layer
    }()
    lazy var maskView:UIImageView = {
        let maskView = UIImageView(frame: self.viewMain.bounds)
        maskView.contentMode = .ScaleAspectFit
        return maskView
    }()
    
    private func createShapeLayer() -> CAShapeLayer {

            shapeLayer.path = nil
            let layer = createShapeLayer()
            layer.path = builder.end()
            layers.append(layer)
            UIGraphicsBeginImageContext(image.size)
            let context = UIGraphicsGetCurrentContext()!
            layer.renderInContext(context)
            maskView.image?.drawInRect(CGRect(origin: .zero, size: image.size))
            maskView.image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
        default:
            shapeLayer.path = nil
        }
