Commit 83ac4df9 authored by toby's avatar toby

random color, center square

parent 55b61a3c
......@@ -18,6 +18,10 @@ func CGRectFromOrigin(view: UIView, xPercent: CGFloat, yPercent: CGFloat, width:
return CGRect(x: x, y: y, width: width, height: height)
}
func randFloat() -> CGFloat {
return CGFloat(Float(arc4random()) / Float(UINT32_MAX))
}
class ViewController: UIViewController {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
......@@ -38,8 +42,10 @@ class ViewController: UIViewController {
@IBAction func newBlock(sender : AnyObject) {
let location = sender.locationInView(view)
let block = UIView(frame: CGRect(x: location.x, y: location.y, width: 10, height: 10))
block.backgroundColor = UIColor.grayColor()
var block: UIView
block = UIView(frame: CGRect(x: location.x, y: location.y, width: 10, height: 10))
block.center = location
block.backgroundColor = UIColor.init(red: randFloat(), green: randFloat(), blue: randFloat(), alpha: 1)
view.addSubview(block)
gravity.addItem(block)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment