             
             self.anchorPoint = closestCorner
             
-            // find the angle of the touch point
-            // zero is horizontal
-            
-            let angle = angleOfTouchPoint(touchPoint, fromPoint: closestCorner)
-            
-            let colour = self.gradientView.colourAtPoint(touchPoint)
-            
-            self.startColour = colour
-            
-            var hue : CGFloat = 0
-            var saturation : CGFloat = 0
-            var brightness : CGFloat = 0
-            var alpha : CGFloat = 0
-            colour.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
-            
-            var wheel = ColourWheel(frame : CGRectMake(0, 0, 200, 200))
-            wheel.center = closestCorner
-            wheel.saturation = saturation
-            wheel.brightness = brightness
-            wheel.startHue = hue
-            wheel.startAngle = angle
-            
-            self.view.addSubview(wheel)
-            wheel.grow(nil)
-            
-            self.colourWheel = wheel
-            self.startAngle = angle
-            self.startColour = colour
+            
             
             // calculate which colour to change
             
             let gradientAngle = self.gradientView.rotation
-            NSLog("gradient is at \(gradientAngle)")
             
             // create a vector through the centre of the screen, at the given angle
             let y = (CGRectGetWidth(self.view.bounds) / 2) * tan(gradientAngle)
             
             let a = CGPointMake(0, (CGRectGetHeight(self.view.bounds) / 2) - y)
             let b = CGPointMake(CGRectGetWidth(self.view.bounds), (CGRectGetHeight(self.view.bounds) / 2) + y)
-            
-            NSLog("vector runs from \(a) to \(b)")
             
             if gradientAngle > CGFloat(-M_PI_2) && gradientAngle < CGFloat(M_PI_2) {
                 if crossProduct(a, b: b, c: touchPoint) > 0 {

        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.scrollView.frame = self.view.bounds
        self.gradientView.frame = self.scrollView.bounds;
        self.view.addSubview(self.scrollView)
        
        self.scrollView.delegate = self
        
        let rotate = UIRotationGestureRecognizer(target: self, action: "handleRotation:")
        rotate.delegate = self
        self.view.addGestureRecognizer(rotate)
        
        let tap = UITapGestureRecognizer(target: self, action: "handleTap:")
        self.view.addGestureRecognizer(tap)
        
        let longPress = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
        self.view.addGestureRecognizer(longPress)
        
    }
    
    func saveGradient () {
        self.saveState = .Saving
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, 0.0)
        self.view.drawViewHierarchyInRect(self.view.bounds, afterScreenUpdates: false)
        let screenshot = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        // convert to PNG so that it doesn't save a JPEG
        let pngData = UIImagePNGRepresentation(screenshot)
        let gradient = UIImage(data: pngData)
        UIImageWriteToSavedPhotosAlbum(gradient, self, "image:didFinishSavingWithError:contextInfo:", nil)
    }
    
    func image(image : UIImage, didFinishSavingWithError error : NSError!, contextInfo : UnsafePointer<Void>) {
        if error != nil {
            var alertController : UIAlertController?
            
            if error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError {
                alertController = UIAlertController(title: NSLocalizedString("unable_to_save", comment: ""), message: NSLocalizedString("cannot_access_photos", comment: ""), preferredStyle: .Alert)
                
            } else {
                alertController = UIAlertController(title: NSLocalizedString("unable_to_save", comment: ""), message: error.localizedDescription, preferredStyle: .Alert)
            }
            
            alertController!.addAction(UIAlertAction(title: NSLocalizedString("close", comment: ""), style: .Cancel, handler: nil))
            self.presentViewController(alertController!, animated: true, completion: { () -> Void in
                self.saveState = .Idle
            })
            
        } else {
            self.saveState = .Saved
            self.showSaveIndicator()
        }
    }
    
    func showSaveIndicator () {
        let btn = self.saveIndicator
        btn.center = self.view.center
        btn.transform = CGAffineTransformMakeScale(0.01, 0.01)
        self.view.addSubview(btn)
        btn.grow(nil)
    }
    
    func hideSaveIndicator () {
        let btn = self.saveIndicator
        btn.shrink { (finished : Bool) -> () in
            btn.removeFromSuperview()
            self.saveState = .Idle
        }
    }
    
    func sharePressed (button : UIButton) {
        
    }
    
    func viewForZoomingInScrollView(scrollView: UIScrollView!) -> UIView! {
        return self.gradientView
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func prefersStatusBarHidden() -> Bool {
        return true;
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.becomeFirstResponder()
    }
    
    override func viewWillDisappear(animated: Bool) {
        self.resignFirstResponder()
        super.viewWillDisappear(animated)
    }

    override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent) {
        if motion == .MotionShake {
            self.gradientView.changeGradient(true)
            AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
        }
        super.motionBegan(motion, withEvent: event)
    }
    
}


                }
            }
            
            // find the angle of the touch point
            // zero is horizontal
            
            let angle = angleOfTouchPoint(touchPoint, fromPoint: closestCorner)
            
            let colour = self.gradientView.colorAtPosition(self.colourToChange)
            
            var hue : CGFloat = 0
            var saturation : CGFloat = 0
            var brightness : CGFloat = 0
            var alpha : CGFloat = 0
            colour.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
            
            var wheel = ColourWheel(frame : CGRectMake(0, 0, 200, 200))
            wheel.center = closestCorner
            wheel.saturation = saturation
            wheel.brightness = brightness
            wheel.startHue = hue
            wheel.startAngle = angle
            
            self.view.addSubview(wheel)
            wheel.grow(nil)
            
            self.colourWheel = wheel
            self.startAngle = angle
            self.startColour = colour
            
            
        } else if gr.state == .Changed {
          
            // update the gradient with the colour from the wheel
