     func endPointForAngle(angle : CGFloat) -> CGPoint {
         return CGPointMake(0.5 - (sin(angle) / 2.0), 0.5 + cos(angle) / 2.0)
     }
+    
+    func randomAngle() -> CGFloat {
+        return CGFloat(arc4random_uniform(1000)) / 1000.0 * CGFloat(M_PI)
+    }
 }
 
 class GradientView : UIView {
+
+    var gradient : CGGradientRef?
     
     var rotation : CGFloat = 0.0 {
         willSet(newRotation) {
             let layer : GradientLayer = self.layer as GradientLayer
             layer.rotate(newRotation);
         }
-    }
-    
-    func randomAngle() -> CGFloat {
-        return CGFloat(arc4random_uniform(1000)) / 1000.0 * CGFloat(M_PI)
+        didSet(newRotation) {
+            self.setNeedsDisplay()
+        }
     }
     
     override func willMoveToSuperview(newSuperview: UIView?) {

    
    func changeGradient(animated : Bool) {
        
        let newColours = NSMutableArray.array()
        for _ in 1...numberOfColours {
            newColours.addObject(UIColor.randomColour().CGColor)
        }

        if (animated) {
            let anim = CABasicAnimation(keyPath: "colors")
            anim.fromValue = self.colors
            anim.toValue = newColours
            anim.duration = animationDuration
            self.addAnimation(anim, forKey: "changeColours")
        }
        
        self.colors = newColours;
    }
    
    func rotate(angle : CGFloat) {

    }
    
    func changeGradient(animated : Bool) {
        
        let layer : GradientLayer = self.layer as GradientLayer
        layer.changeGradient(animated)

    }
    
    override class func layerClass() -> AnyClass {
